当前位置: 代码迷 >> Sql Server >> 请教这个触发器应该如何写
  详细解决方案

请教这个触发器应该如何写

热度:71   发布时间:2016-04-27 19:52:29.0
请问这个触发器应该怎么写?
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
  相关解决方案