Escolar Documentos
Profissional Documentos
Cultura Documentos
and
User-Defined Functions
TCS Internal
1
Scope
SQL Extension
Stored Procedure
User-Defined Functions
TCS Internal
2
SQL Extension
Batches:
TCS Internal
3
SQL Extension
Scripts
Scripts are a series of batches submitted together.
SELECT...
UPDATE... BATCH
GO
BEGIN TRAN
......... BATCH
SCRIPT
COMMIT TRAN
GO
...........
.......... BATCH
GO
TCS Internal
4
SQL Extension
TCS Internal
5
SQL Extension
You cannot alter the table and reference the new columns in
the same batch.
TCS Internal
6
SQL Extension – Flow-Control
TCS Internal
7
SQL Extension – Flow-Control
BEGIN…END
Syntax:
BEGIN
[SQL statements | statement block]
END
If BEGIN and END are not used, only the first statement immediately
following the IF...ELSE or WHILE is executed.
TCS Internal
8
SQL Extension – Flow-Control
IF…ELSE BLOCK
TCS Internal
9
SQL Extension – Flow-Control
WHILE Construct
TCS Internal
10
SQL Extension – Flow-Control
TCS Internal
11
SQL Extension
EXECUTE Statement
TCS Internal
12
SQL Extension
CASE Expression
TCS Internal
13
SQL Extension
TCS Internal
14
SQL Extension
TCS Internal
15
SQL Extension
Local Variables
Syntax:
TCS Internal
16
SQL Extension
Global Variables
TCS Internal
17
SQL Extension
RETURN
GOTO
RAISEERROR
WAITFOR
TCS Internal
18
RETURN Statements
RETURN Statements
TCS Internal
19
GOTO Label
TCS Internal
20
RAISERROR Statement
Syntax:
TCS Internal
21
WITH LOG
Logs the error in the server error log and the event log.
Generally required for messages with a severity level of 19 through
25
TCS Internal
22
WAIT FOR
Syntax:
TCS Internal
23
Stored Procedure
TCS Internal
24
System Stored Procedure
TCS Internal
25
Create a Stored Procedure
Example:
TCS Internal
26
Execute the Stored Procedure
Example:
TCS Internal
27
User-Defined Functions
Procedure
Functions
Procedure
Functions
TCS Internal
28
Creation of User-Defined Functions
Syntax:
TCS Internal
29
Example of User-Defined Functions
Example
TCS Internal
30
Summary
SQL Extension
Stored Procedure
User-Defined Functions
TCS Internal
31