begin try
begin tran
insert into table1
values(1,'First row','First row')
insert into table1
values(2,null,'Second row');
insert into table1
values(3,'Third row','Third row')
commit tran;
end try
begin catch
select ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE()AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
RAISERROR('Error in Transaction!',14,1)
rollback tran
end catch
包含实际错误信息 :
begin catch
declare @error nvarchar(max)
set @error='Error: '+ Error_Message();
RAISERROR(@error,14,1)
rollback tran
end catch