日期:2014-05-18 浏览次数:20497 次
declare @id int
begin tran
delete tableName where id=@id
if(@@error<>0)
rollback tran
else
commit tran
------解决方案--------------------
begin Transaction
begin Try
----------------------------------
delete from 表名 where 条件
---------------------------------
commit Tran
end Try
begin Catch
rollback Tran
declare @sTemp varchar(1000)
select @sTemp=ERROR_MESSAGE()
raiserror(@sTemp,16,1)
end Catch
------解决方案--------------------
SQL代码关键词:
事务(transaction),
提交(commit),
回滚(rollback),
开始(begin),
结束(end).
------解决方案--------------------
--2005 & 2008
Begin Try
Begin tran
--SQL 語句(Insert\Update\Delete)
Commit Tran
End Try
Begin Catch
Declare @Error nvarchar(2047)
Set @Error=Error_message()
Raiserror 50001 @Error
Rollback Tran
End Catch
Go
--2000
begin tran
--單條 SQL 語句(Insert\Update\Delete)
If @@ERROR <>0
Goto ErrFlag
--單條 SQL 語句(Insert\Update\Delete)
If @@ERROR <>0
Goto ErrFlag
--單條 SQL 語句(Insert\Update\Delete)
If @@ERROR <>0
Goto ErrFlag
Commit Tran
Goto ExitFlag
ErrFlag:
Rollback Tran
ExitFlag: