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

前端 未结 5 945
自闭症患者
自闭症患者 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:17

    These 2 statements are entirely different.

    BEGIN..END mark a block of code, eg in an if statement

    IF @something = 1
    BEGIN
      -- Do something when @something is equal to 1
    END
    

    BEGIN TRANS..COMMIT TRANS wrap the enclosing block in a transaction, and depending on server settings will rollback the transaction if an error occurs.

提交回复
热议问题