SQL Server BEGIN/END vs BEGIN TRANS/COMMIT/ROLLBACK

前端 未结 5 984
自闭症患者
自闭症患者 2020-12-30 21:36

I have been trying to find info on the web about the differences between these statements, and it seems to me they are identical but I can\'t find confirmation of that or an

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 22:16

    The regular BEGIN and END are not used for transactions. Instead, they are just for indicating that some block of code is a single unit, much like braces {} in C#/C++/Java.

    If you have an IF statement or a WHILE loop that does 10 things, you need to enclose them in BEGIN/END so that SQL Server knows that that whole list of 10 statements should be executed as a part of that condition.

提交回复
热议问题