How to create a transaction and rollback in SQL Server

Useful Microsoft SQL Server code snippets.
Post Reply
Z12
Site Admin
Posts: 20
Joined: Thu Sep 30 2021, 11:47
Location: UK
Contact:

How to create a transaction and rollback in SQL Server

Post by Z12 »

To create a transaction in SQL Server:

Code: Select all

BEGIN TRANSACTION;  
INSERT INTO MyTableName VALUES(1);  
INSERT INTO MyTableName VALUES(2); 
To commit a transaction in SQS Server:

Code: Select all

 
COMMIT TRANSACTION;  
To roll back a transaction in SQL Server:

Code: Select all

  
ROLLBACK TRANSACTION;  
If you find Z12 Web Tools useful and would like to show your appreciation...
Why not Buy Me A Coffee to say: Thank You!


Post Reply