存储过程中的多个插入语句 [英] Multiple insert statement in Stored Procedure

查看:88
本文介绍了存储过程中的多个插入语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的存储过程中有四个insert语句,如果有任何原因,如果第四个insert语句显示一些错误,数据是否会插入到程序中所有成功执行的语句中,如果是,请分享原因。

解决方案

是的,因为INSERT语句立即生效。如果这不是您想要的,那么您需要将命令放在TRANSACTION中,以便您可以作为一个单元提交或取消它们(回滚)。



编辑AL:这是关于 SQL Server事务和错误处理 [ ^ ]

I have four insert statement in my stored procedure, if any reason if fourth insert statement showing some error, does data will be inserted in all the successfully executed statement within procedure, if yes , please share the reason.

解决方案

Yes it will because the INSERT statements take immediate effect. If this isn't what you want then you need to put your commands in a TRANSACTION so that you can commit or cancel them (rollback) as a single unit.

EDIT AL: here is a good article on SQL Server Transactions and Error Handling[^]


这篇关于存储过程中的多个插入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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