三表关联,触发器问题,请高手指点赐教,在线等!不胜感激!谢谢!

我是一只小小小的菜鸟 2008-03-18 06:54:14


表1:CProStardOut ,字段如下

PrintID DXUnit
1 AAA
2 BBB
3 CCC
4 DDD
5 EEE



表2:CproGoldOutDetail 字段如下

PrintID ProdNo
1 001
2 002
3 003
4 004
5 005



表3:CProGoldBar 字段如下

ProdNo IsOut
001 1
002 1
003 1
004 1
005 1

我想在表1:CProStardOut中写个触发器,让表1:CProStardOu删除PrintID 为1的时候
将表3:CProGoldBar 中ProdNo字段中为001的IsOut字段的值修改成0;
三个表的关系很简单,表1的PrintID关联表2的PrintID,表2的ProdNo关联表三的ProdNo;
...全文
121 7 点赞 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xingchenbbs 2008-03-19
星辰技术社区:www.netcsharp.cn,我们将帮您以最快的速度找到最佳的解决方案
  • 打赏
  • 举报
回复
-狙击手- 2008-03-18
create trigger triggername
on CProStardOut
for delete
as
update c
set c.isout = 0
from cprogoldbar c
left join cprogoldoutdetail b on c.prodno = b.prodno
left join deleted a on a.PrintID = b.PrintID
end
  • 打赏
  • 举报
回复
中国风 2008-03-18
create trigger del_CProStardOut on CProStardOut
for delete
as
update a
set IsOut=0
from
CProGoldBar a
join
CproGoldOutDetail b on a.ProdNo =b.ProdNo
join
deleted c on c.PrintID =b.PrintID
  • 打赏
  • 举报
回复
$扫地僧$ 2008-03-18
create table CProStardOut
(
PrintID int,
DXUnit varchar(10)
)
Go
create table CproGoldOutDetail
(
PrintID int,
ProdNo varchar(10)
)
Go
create table CProGoldBar
(
ProdNo varchar(10),
IsOut int
)
Go

insert CProStardOut select 1,'AAA'
insert CProStardOut select 2,'BBB'
insert CProStardOut select 3,'CCC'
insert CProStardOut select 4,'DDD'
insert CProStardOut select 5,'EEE'
Go

insert CproGoldOutDetail select 1,'001'
insert CproGoldOutDetail select 2,'002'
insert CproGoldOutDetail select 3,'003'
insert CproGoldOutDetail select 4,'004'
insert CproGoldOutDetail select 5,'005'
Go

insert CProGoldBar select '001',1
insert CProGoldBar select '002',1
insert CProGoldBar select '003',1
insert CProGoldBar select '004',1
insert CProGoldBar select '005',1
Go



CREATE TRIGGER TEMP_SC ON CProStardOut
AFTER delete
as
update CProGoldBar set IsOut=0
from deleted D,
CproGoldOutDetail A1,
CProGoldBar B1
where D.PrintID=A1.PrintID and A1.ProdNo=B1.ProdNo
Go

delete from CProStardOut where PrintID=1
Go

select * from CProGoldBar
Go
  • 打赏
  • 举报
回复
狙击手大哥!提示有错误啊!在"="附近有语法错误!
  • 打赏
  • 举报
回复
pt1314917 2008-03-18

create trigger triggername on CProStardOut for delete
as
update CProGoldBar set isout = 0 from cprogoldbar c
left join cprogoldoutdetail b on c.prodno = b.prodno
left join deleted a on a.PrintID = b.PrintID
end

  • 打赏
  • 举报
回复
-狙击手- 2008-03-18
表1:CProStardOut ,字段如下
PrintID DXUnit
1 AAA

表2:CproGoldOutDetail 字段如下

PrintID ProdNo
1 001
2 002

表3:CProGoldBar 字段如下

ProdNo IsOut
001 1
002 1
create trigger triggername
on CProStardOut
for delete
as
update c.isout = 0
from cprogoldbar c
left join cprogoldoutdetail b on c.prodno = b.prodno
left join deleted a on a.PrintID = b.PrintID
end
  • 打赏
  • 举报
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-03-18 06:54
社区公告
暂无公告