数据库事务
时间:2010-10-15 来源:goodluckzxj
数据库事务是数据库处理的最小单位,可由多个操作组成。特点是这些操作要么都执行要么都不执行即回滚。
以下程序段aa中有两个操作,一个是插入表格,一个是删除表格,定义为一个事务。
ALTER proc [dbo].[aa] as begin begin transaction//在标记事务开始标记 insert into OldTaskInfo select RegXh,Time,SectionId,CardId from TaskInfo where Time between '2010-1-1' and GETDATE() if @@error <> 0 begin rollback transaction--发生错误则回滚事务,无条件退出l return end
delete from TaskInfo where Time between '2010-1-1' and GETDATE() if @@error <> 0 begin rollback tran return end commit transaction --两条语句都完成,提交事务 end
ALTER proc [dbo].[aa] as begin begin transaction//在标记事务开始标记 insert into OldTaskInfo select RegXh,Time,SectionId,CardId from TaskInfo where Time between '2010-1-1' and GETDATE() if @@error <> 0 begin rollback transaction--发生错误则回滚事务,无条件退出l return end
delete from TaskInfo where Time between '2010-1-1' and GETDATE() if @@error <> 0 begin rollback tran return end commit transaction --两条语句都完成,提交事务 end
相关阅读 更多 +