Mega Code Archive

 
Categories / MSSQL Tutorial / Transaction
 

Inserting a Row into MyTable and Rolling Back the Transaction

4> 5> 6> CREATE TABLE MyTable ( 7>  key_col int NOT NULL IDENTITY (1,1), 8>  abc     char(1) NOT NULL 9> ) 10> INSERT INTO MyTable VALUES ('a') 11> INSERT INTO MyTable VALUES ('b') 12> INSERT INTO MyTable VALUES ('c') 13> SELECT * FROM MyTable ORDER BY key_col 14> 15> BEGIN TRAN 16>  INSERT INTO MyTable VALUES ('e') 17> ROLLBACK TRAN 18> INSERT INTO MyTable VALUES ('f') 19> SELECT 20>  * 21> FROM 22>  MyTable 23> ORDER BY 24>  key_col 25> 26> 27> drop table MyTable 28> GO (1 rows affected) (1 rows affected) (1 rows affected) key_col     abc ----------- ---           1 a           2 b           3 c (1 rows affected) (1 rows affected) key_col     abc ----------- ---           1 a           2 b           3 c           5 f (4 rows affected) 1>