Redian新闻
>
Why does this Stored procedure fail ?
avatar
Why does this Stored procedure fail ?# Database - 数据库
b*r
1
I have a stored procedure
ALTER PROC mysp
@ID int,
@CID int,
@Status varchar(10) = NULL
AS
UPDATE mytable
SET [email protected], Status = @Status,
WHERE ID = @ID
declare @ClosureFlag char(1)
set @ClosureFlag = '0'
if @Status = '2'
begin
--update myothertable
delete from myanothertable where CID = @CID
INSERT INTO mythirdtable (CID, 'something deleted')
VALUES (@CID, @message)
-- set the flag for C# code use
set @ClosureFlag = '1'
end
select @ClosureFlag as ClosureFlag
Most time it r
avatar
aw
2
My understanding is that this entire stored procedure is run within a batch so
it should beheave like running in a transaction, if there is any error
updating myothertable and mythirdtable, it should rollback.
这个ASSUMPTION不对,SP就是一堆SQL,你在里面不指定TRANSACTION,它不会给你自动的
。象你这种又是UPDATE又是DELETE,前后还相关的,每步应该查错,如果有,叫它ROLL
BACK。

so

【在 b******r 的大作中提到】
: I have a stored procedure
: ALTER PROC mysp
: @ID int,
: @CID int,
: @Status varchar(10) = NULL
: AS
: UPDATE mytable
: SET [email protected], Status = @Status,
: WHERE ID = @ID
: declare @ClosureFlag char(1)

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。