Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davepcallan/17365cbaa200062d4fd1056f0f255c05 to your computer and use it in GitHub Desktop.
Save davepcallan/17365cbaa200062d4fd1056f0f255c05 to your computer and use it in GitHub Desktop.
Sample SQL which shows rollback IS possible in SQL Server
-- 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