触发器写法

liyuyu 2008-04-02 11:37:04
有表A(A_1,A_2) 表B(B_1,B_2)
假设update前A_1叫old_A_1,old_A_2
假设update后A_1叫new_A_1,new_A_2
if old_A_2 ='UP' then
UPdate B set B_2='UUUUU' where old_A_1=B_1;

if old_A_2 ='DOWN' then
UPdate B set B_2='DDDDD' where old_A_1=B_1;
if new_A_2='UP' then
UPdate B set B_2='FFFF' where new_A_1=B_1;

if new_A_2='DOWN' then
UPdate B set B_2='GGGG' where new_A_1=B_1;
...全文
89 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wh110 2008-04-03
[Quote=引用 6 楼 bqb 的回复:]
SQL codecreate trigger t_update on A
after update
as
begin
update B set B.B_2=case when A.A_2='UP' then 'UUUUU'
when A.A_2='DOWN' then 'DDDDD'
when A.A_2='UP' and B.B_2='UUUUU' then 'FFFF'
when A.A_2='DOWN' and B.B_2='DDDDD' then 'GGGG'
end
from B,A
where B.B_1=A.A_1
end
[/Quote]
回复
liyuyu 2008-04-02
谢谢bqb,非常谢谢
回复
bqb 2008-04-02
create trigger t_update on A 
after update
as
begin
update B set B.B_2=case when A.A_2='UP' then 'UUUUU'
when A.A_2='DOWN' then 'DDDDD'
when A.A_2='UP' and B.B_2='UUUUU' then 'FFFF'
when A.A_2='DOWN' and B.B_2='DDDDD' then 'GGGG'
end
from B,A
where B.B_1=A.A_1
end
回复
bqb 2008-04-02
[Quote=引用楼主 liyuyu 的帖子:]
有表A(A_1,A_2) 表B(B_1,B_2)
假设update前A_1叫old_A_1,old_A_2
假设update后A_1叫new_A_1,new_A_2
if old_A_2 ='UP' then
UPdate B set B_2='UUUUU' where old_A_1=B_1;

if old_A_2 ='DOWN' then
UPdate B set B_2='DDDDD' where old_A_1=B_1;
if new_A_2='UP' then
UPdate B set B_2='FFFF' where new_A_1=B_1;

if new_A_2='DOWN' then
UPdate B set B_2='GGGG' where new_A_…
[/Quote]
create trigger t_update on A 
after update
as
begin
update B set B.B_2=case when i.A_2='UP' then 'UUUUU'
when i.A_2='DOWN' then 'DDDDD'
when i.A_2='UP' and B.B_2='UUUUU' then 'FFFF'
when i.A_2='DOWN' and B.B_2='DDDDD' then 'GGGG'
end
from B,inserted i
where B.B_1=i.A_1
end
回复
青锋-SS 2008-04-02
[Quote=引用 3 楼 sdhylj 的回复:]
create trigger t_1
on a
for update
as
update b set b_2='UUUUU' from a where a_2='UP' and A_1=B_1
UPdate B set B_2='DDDDD' from a where A_2 ='DOWN' and A_1=B_1;
UPdate B set B_2='GGGG' from inserted i where i.A_2='DOWN' and i.A_1=B_1


[/Quote]
回复
青锋-SS 2008-04-02
create trigger t_1
on a
for update
as
update b set b_2='UUUUU' where a_2='UP' and A_1=B_1
UPdate B set B_2='DDDDD' where A_2 ='DOWN' and old_A_1=B_1;
UPdate B set B_2='GGGG' from inserted i where i.A_2='DOWN' and i.A_1=B_1

回复
-狙击手- 2008-04-02
你这逻辑有点问题吧?
回复
wangxuelid 2008-04-02
if new_A_2='DOWN' then --取掉then,
UPdate B set B_2='GGGG' where new_A_1=B_1;
回复
fuda_1985 2008-04-02
学习,
正好不会写触发器~~
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

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