日期:2014-05-18  浏览次数:20603 次

请问这个触发器应该怎么写?
a表
id   name   content
1     a1       aaa
2     a2       bbb
b表
id   name
1     a1
2     a2
a和b的内容字段数据基本一样,要求在更新a表中id   =   1的数据库也更新b表中对应的内容。
在a   update   a   set   name   =   'aname '   where   id   =   1   后更新b
update   b   set   name   =   a表中对应的name内容   where   id   =   a表中更新的对应id


------解决方案--------------------

create trigger triggerName On a
for Update
as
Update b set b.name=t.name
from Inserted t inner Join b on t.id=b.id
go
------解决方案--------------------
update b set b.name=a.name from b表 b join inserted c on b.id = c.id where c.id=1