--@@ERROR的使用
DECLARE @del_error int, @ins_error int
BEGIN TRAN
-- Execute the INSERT statement.
INSERT into table2 VALUES('dd','ds',34,2)
SELECT @del_error = @@ERRORIF @del_error = 0
BEGIN
   -- Success. Commit the transaction.
   PRINT 10 
   COMMIT TRAN
END
ELSE
BEGIN
      PRINT 20 
   ROLLBACK TRAN
END
GO在查询分析器里,
如果是重复键,那么出错后可以跳到print 20这里,如果是表名不对,列名不对这些问题,直接报错,出错后根本不执行@@error设定的错误跳转.