这样的触发器应该如何写

Cervisia 2008-01-18 03:10:39
当表T1的字段A被更新时,同时更新表T2中的字段A。条件:T1.A=T2.A
...全文
49 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
JL99000 2008-01-18
  • 打赏
  • 举报
回复
怎么更新关键字。。。。
Cervisia 2008-01-18
  • 打赏
  • 举报
回复
谢谢各位,小梁同志的最好。:)
wzy_love_sly 2008-01-18
  • 打赏
  • 举报
回复
小梁的就对
Cervisia 2008-01-18
  • 打赏
  • 举报
回复
A就是关键字呀。这就象一个二级数据库一样。T1是一级数据库,T2是二级数据库。
当T1的关键值被更新时,就更新T2中的关键字A,且条件是:T2没被更新时的关键字A必须与没被更新时的T1的关键字A相等。请问如何写。
liangCK 2008-01-18
  • 打赏
  • 举报
回复
create trigger tri on t1
for update
as
update a set t2.A=i.A
from t2 a,inserted i,deleted d
where a.A=d.A
go
marco08 2008-01-18
  • 打赏
  • 举报
回复

create trigger upd_T1 on T1 for update
as
declare @id int
declare @A int
select @id=id,@A=A from inserted

if update(A)
begin
update T2 set A=@A
where id=@id
end
tim_spac 2008-01-18
  • 打赏
  • 举报
回复
create triger tr_up_t1
for update as begin
update t2 set a=inserted.a
from t2, inserted
where t2.id=inserted.id

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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