January 27, 2015 at 11:01 pm
can truncate and delete rollback when we use transactions?
January 27, 2015 at 11:09 pm
Yes, both can but do a simple test to prove it to yourself.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 27, 2015 at 11:31 pm
USE tempdb
GO
CREATE TABLE myTest (Id INT,Name VARCHAR(256))
GO
INSERT INTO myTest (Id,Name) VALUES (1,'abc')
INSERT INTO myTest (Id,Name) VALUES (2,'def')
INSERT INTO myTest (Id,Name) VALUES (3,'ert')
INSERT INTO myTest (Id,Name) VALUES (4,'xyz')
GO
SELECT * FROM myTest
BEGIN TRAN
TRUNCATE TABLE myTest
ROLLBACK TRAN
SELECT * FROM myTest
GO
SELECT * FROM myTest
BEGIN TRAN
DELETE FROM myTest
ROLLBACK TRAN
SELECT * FROM myTest
DROP TABLE myTest
January 28, 2015 at 7:21 am
satishkmr538 (1/27/2015)
can truncate and delete rollback when we use transactions?
Sounds like an interview question to me. 😉
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply