When do I need to use Begin / End Blocks and the Go keyword in SQL Server?

后端 未结 6 1611
借酒劲吻你
借酒劲吻你 2020-11-29 18:08

Can someone tell me when and where I need to use begin and end blocks in SQL Server?
Also, what exactly does the Go keyword do?

6条回答
  •  伪装坚强ぢ
    2020-11-29 18:21

    You need BEGIN ... END to create a block spanning more than one statement. So, if you wanted to do 2 things in one 'leg' of an IF statement, or if you wanted to do more than one thing in the body of a WHILE loop, you'd need to bracket those statements with BEGIN...END.

    The GO keyword is not part of SQL. It's only used by Query Analyzer to divide scripts into "batches" that are executed independently.

提交回复
热议问题