这个交易怎么写?

houzy123 2003-05-16 10:56:24
我的意思是一旦删除@zcl,将相关的几个表同时删除
CREATE PROCEDURE delete_zcl
@zcl varchar(20)
AS
if @zcl is not null
begin
begin transaction
delete from cb_djb where zcl=@zcl --可能不存在zcl=@zcl的记录
delete from cb_header where zcl=@zcl
delete from djb where zcl=@zcl
delete from dibparent where zcl=@zcl
if @@ERROR!=0
begin
ROLLBACK transaction
end
commit tran
end
GO
...全文
61 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
愉快的登山者 2003-05-16
  • 打赏
  • 举报
回复
CREATE PROCEDURE delete_zcl
@zcl varchar(20)
AS
if @zcl is not null
begin
begin transaction
delete from cb_djb where zcl=@zcl --可能不存在zcl=@zcl的记录
if @@ERROR!=0
begin
ROLLBACK transaction
return
end
delete from cb_header where zcl=@zcl
if @@ERROR!=0
begin
ROLLBACK transaction
return
end
delete from djb where zcl=@zcl
if @@ERROR!=0
begin
ROLLBACK transaction
return
end
delete from dibparent where zcl=@zcl
if @@ERROR!=0
ROLLBACK transaction
else
commit transaction
end
return
GO
liuyun2003 2003-05-16
  • 打赏
  • 举报
回复
CREATE PROCEDURE delete_zcl
@zcl varchar(200)
AS
if @zcl is not null
begin
begin transaction
delete cb_djb where zcl=@zcl
if @@ERROR<>0
begin
ROLLBACK transaction
end

delete cb_header where zcl=@zcl
if @@ERROR<>0
begin
ROLLBACK transaction
end

delete djb where zcl=@zcl
if @@ERROR<>0
begin
ROLLBACK transaction
end

delete dibparent where zcl=@zcl
if @@ERROR<>0
begin
ROLLBACK transaction
end
else
begin
commit tran
end
end
GO
CrazyFor 2003-05-16
  • 打赏
  • 举报
回复
CREATE PROCEDURE delete_zcl
@zcl varchar(20)
AS
declare @err int
set @err=0
if @zcl is not null
begin
begin transaction
delete from cb_djb where zcl=@zcl --可能不存在zcl=@zcl的记录
if @@erroe<>0
@err=1
delete from cb_header where zcl=@zcl
if @@erroe<>0
@err=1

delete from djb where zcl=@zcl
if @@erroe<>0
@err=1

delete from dibparent where zcl=@zcl
if @@erroe<>0
@err=1

if @err=1
begin
ROLLBACK transaction
end
commit tran
end
GO

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧