小白求SQL 触发器:现有A,B两表,要求B表新增或更改时,A表中的PRICE 字段更新到B中的PRICE ,为空不更新
A:IDNAMEPRICE1book15.002cup10.00------------------------------B:IDNAMEPRICEgeshu1book...
A:
ID NAME PRICE
1 book 15.00
2 cup 10.00
------------------------------
B:
ID NAME PRICE geshu
1 book 15.00 10
2 cup 10.00 20
MB:
MB001 MB002 MB003
1 book 15.00
2 cup 10.00
-----
TB:
TB004 TB005 TB007 geshu
1 book 15.00 10
2 cup 10.00 20
MB表是先有的,那么我在插入或者更改TB表时,我想把MB表的MB003更新到TB表的TB007 (MB001=TB004) 展开
ID NAME PRICE
1 book 15.00
2 cup 10.00
------------------------------
B:
ID NAME PRICE geshu
1 book 15.00 10
2 cup 10.00 20
MB:
MB001 MB002 MB003
1 book 15.00
2 cup 10.00
-----
TB:
TB004 TB005 TB007 geshu
1 book 15.00 10
2 cup 10.00 20
MB表是先有的,那么我在插入或者更改TB表时,我想把MB表的MB003更新到TB表的TB007 (MB001=TB004) 展开
2个回答
展开全部
create TRIGGER B_U
ON dbo.B
for insert UPDATE
AS
if exists(select price from inserted where price is not null)
update dbo.B
set PRICE
from inserted,dbo.A
where inserted.ID=dbo.B.ID and inserted.NAME =dbo.A.NAME
ON dbo.B
for insert UPDATE
AS
if exists(select price from inserted where price is not null)
update dbo.B
set PRICE
from inserted,dbo.A
where inserted.ID=dbo.B.ID and inserted.NAME =dbo.A.NAME
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询