问题将与EMAIL表上缺少主键有关。触发器与不变的主键配合使用效果最佳。
另外,如果某行变为非主要行,您该如何从PERSON中删除该条目?
因此,在问题域中似乎仍然存在一些悬而未决的问题,但这是对触发器的外观的一种刺探。您可以添加一些东西来查找实际发生更改的行-但要注意NULL。
CREATE TRIGGER EMAIL_update ON UPDATEASBEGIN UPDATE PERSON SET EMAIL = i.EMAILADDRESS FROM PERSON INNER JOIN inserted AS i ON i.PERSonID = PERSON.PERSonID INNER JOIN deleted AS d -- could try changing this to a left join and use same trigger for INSERT ON -- what? could use PERSONID, but it's not unique WHERe i.ISPRIMARY = 1 -- This helps with uniqueness, but what about things leaving primary? -- AND i.EMAILADDRESS <> PERSON.EMAIL -- Could add this (what about NULLs?)END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)