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

一个问题请大家帮帮忙啊!
表A有字段nID,name表B有字段nID,name
有没有什么办法在插入A中的nID的时候将B中相同nID的name自动插入到A的name中来呢?
还有当删除任何一个表中的记录时2个表nID相同的记录都会被删除呢》?

------解决方案--------------------
create trigger it_A on A
instead of insert
as
insert into A(nID,name)
select inserted.nID,b.name
from inserted,B
where inserted.nID=b.nID
GO
create trigger td_A on A
for delete
as
delete from B where nID in (select nID from deleted)