USE tempdb IF OBJECT_ID ('dbo.test') IS NOT NULL DROP TABLE dbo.test GO CREATE TABLE dbo.test ( id INT NOT NULL, CONSTRAINT pk_id PRIMARY KEY (id) ) GO BEGIN TRY BEGIN TRANSACTION INSERT INTO dbo.test(id)VALUES (0 ) INSERT INTO dbo.test(id)VALUES (1 ) INSERT INTO dbo.test(id)VALUES (1 ) INSERT INTO dbo.test(id)VALUES (2 ) COMMIT TRANSACTION END TRY BEGIN CATCH PRINT ERROR_MESSAGE() ROLLBACK END CATCH