Rollback Table after Truncate Command in Sql Server
It is misconception among people that Truncate cannot be rolled back. But in reality Truncate operation can be Rolled Backed before Commit.Here is the Sql query
-- Create table
CREATE TABLE Employee
( EmpID INT PRIMARY KEY,
EmpSalary INT
)
-- Check data before Truncate
SELECT * FROM Employee
BEGIN TRAN
--Truncate Table
TRUNCATE TABLE Employee
GO
SELECT * FROM Employee
GO
--Rollback Transaction
GO
--Check the data
after Rollback
SELECT * FROM Employee
GO
Note:- If Transaction is done, mean Committed then we can not rollback Truncate command from log file but we can restore data using MSSQL Server Management Studio.
Check for difference between Delete and Truncate in next article.
Give your valuable comments it's encourage me to publish new articles.
Comments
Post a Comment