一个以上声明的交易 [英] transaction of more than one statement

查看:72
本文介绍了一个以上声明的交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一个事务中将多个记录插入表中?

如果我可以提交其他所有插入行的回滚。



like



How to insert more than one record into table in one transaction?
If I can then commit otherwise rollback of all inserted rows.

like

declare @i;
set @i=10;
while(@i>0)
begin
insert into table1(salary) values('2000');
set @i=@i-1
end



在上面的示例中它成功运行了五次然后我想回滚五行插入。


In above example It runs successfully for five times then I want to roll back for five rows which are inserted.

推荐答案

你应阅读 TRANSACTION http://www.sqlteam。 com / article / introduction-to-transactions [ ^ ]



在您的情况下:

You should read about TRANSACTION : http://www.sqlteam.com/article/introduction-to-transactions[^]

In your case :
declare @i;
set @i=10;
while(@i>0)
begin
BEGIN TRAN
insert into table1(salary) values('2000');
set @i=@i-1
ROLLBACK TRAN
end


这篇关于一个以上声明的交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆