Introduction to transact SQL

Time:2021-1-26

T-SQL

 

Basic sentence

Comments: single line comments: – multi line comments: / **/

Define the end of batch statement: go

Output statement: Print (expression)

 

data type

 

 

variable

 

 

operator

 

 

function

 

 

 

 

4. Transfer function

Cast (expression as data type): converts the expression display of one data type to another

Convert (data type [(length)], expression, [, style]): convert the expression display of one data type to another data type. When converting date event type data to character type data, you can specify the converted character style.

 

Flow control statement

1. Begin.. end: defines a statement block, similar to curly braces: {}

2. Break: exit the innermost loop

3. Continue: restart the cycle

4. Goto label: unconditional transfer

5. If… Else: conditional branch

6. Return: unconditional exit

7. Waitfor: sets the delay for the execution of the statement

Waitfor time '12:00:00' -- set to execute the following statement at 12:00:00
Wait for delay '00:00:05' - set the following statement to be executed after 5 seconds

8. While: cycle

9. Case: multi branch statement

case 
When logical expression then expression
...
Else expression

 

 

Script file

Script: one or more T-SQL statements

Script file: the file to save the script, with the extension of. SQL