only My site

Wednesday, December 23, 2009

SQL Save, Commit, Rollback Transaction

--Save, Commit, Rollback Transaction
CREATE TABLE #TestTable
(Col1 INT,
Col2 VARCHAR(2),
Col3 VARCHAR(2))
GO
BEGIN TRANSACTION
INSERT INTO #TestTable
VALUES (1,'a','b');

SAVE TRANSACTION Sav1
GO
BEGIN TRANSACTION
UPDATE #TestTable SET Col2 = 'c'
WHERE Col1 = 1;
COMMIT TRANSACTION

ROLLBACK TRANSACTION Sav1;

COMMIT TRANSACTION

SELECT * FROM #TestTable

DROP TABLE #TestTable

No comments: