Skip to content

Instantly share code, notes, and snippets.

@j717273419
Created April 11, 2017 09:14
Show Gist options
  • Save j717273419/ab9dbda684f558a470084f9817aa9de5 to your computer and use it in GitHub Desktop.
Save j717273419/ab9dbda684f558a470084f9817aa9de5 to your computer and use it in GitHub Desktop.
sql server 事务示例
--如果出错,全回滚整个事务
SET XACT_ABORT off
begin tran
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES (GETDATE())
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES (222)
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES ('key04')
commit tran
--如果出错,全回滚整个事务
begin tran
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES (GETDATE())
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES (222)
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES ('key04')
commit tran
roolback
--如果出错,全回滚整个事务
begin try
begin tran
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES (GETDATE())
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES (GETDATE())
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES (GETDATE())
INSERT INTO [dbo].[SsoLog] (Sl_Login_Time) VALUES ('key04')
commit tran
end try
begin catch
rollback
end catch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment