Created
April 5, 2024 16:43
-
-
Save davepcallan/17365cbaa200062d4fd1056f0f255c05 to your computer and use it in GitHub Desktop.
Sample SQL which shows rollback IS possible in SQL Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create Test Table | |
CREATE TABLE TruncateTest (ID INT) | |
INSERT INTO TruncateTest (ID) | |
SELECT 1 | |
UNION ALL | |
SELECT 2 | |
UNION ALL | |
SELECT 3 | |
GO | |
-- Check the data before truncate | |
SELECT * FROM TruncateTest | |
GO | |
-- Begin Transaction | |
BEGIN TRAN | |
-- Truncate Table | |
TRUNCATE TABLE TruncateTest | |
GO | |
-- Check the data after truncate | |
SELECT * FROM TruncateTest | |
GO | |
-- Rollback Transaction | |
ROLLBACK TRAN | |
GO | |
-- Check the data after Rollback | |
SELECT * FROM TruncateTest | |
GO | |
-- Clean up | |
DROP TABLE TruncateTest | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment