--创建测试表
CREATE TABLE Test
(
  Test INT PRIMARY KEY
)

--创建存储过程
ALTER PROC MyTest
@Number1 INT,
@Number2 INT
AS
SET XACT_ABORT ON
 BEGIN TRAN
   BEGIN TRY
      INSERT INTO Test values(@Number1);
      INSERT INTO Test values(@Number2);
   END TRY
   BEGIN CATCH
    IF @@trancount > 0
      ROLLBACK TRAN
   END CATCH
IF @@trancount > 0
    COMMIT TRAN
  
 
--正常执行执行
EXEC MyTest 1,2
--主键约束错误执行
EXEC MyTest 1,2
 --主键约束错误执行
EXEC MyTest 'str1',2

--删除  
DELETE FROM Test;   
--查询
SELECT * FROM Test;