Friday, July 29, 2011

Is TRUNCATE TABLE transactional ?

1: CREATE TABLE tTest ( i INT )  
2: INSERT tTest ( i ) VALUES( 1 ) 
3: INSERT tTest ( i ) VALUES( 1 ) 
4: INSERT tTest ( i ) VALUES( 1 ) 
5: INSERT tTest ( i ) VALUES( 1 ) 
6: 
7: BEGIN TRAN 
8:  TRUNCATE TABLE tTest 
9:  SELECT * FROM tTest 
10: ROLLBACK 
11: 
12: SELECT COUNT(*) FROM tTest 
13: DROP TABLE tTest 
14: 
15: 


So, yes - it is subject to the transaction; also - it is a logged operation, its just that the individual rows are not logged "individually" like they would if you used DELETE.

0 comments:

Post a Comment