我已经创建了一个触发器,并且如果该列已更新,我希望它对列的值执行一个功能,否则我只想正常更新。为了使数据库更易于维护,我不想列出要更新的列,因为我不想在向表中添加/删除列时更新触发器。
CREATE TRIGGER modify_country_code
ON Location
INSTEAD OF UPDATE
AS
BEGIN
IF UPDATE(CountryCode)
BEGIN
-- This works if I am only updating the CountryCode column. But if updating
-- multiple columns, the other columns are not updated (obviously)
UPDATE Location
SET Location.CountryCode = dbo.MyFunction(inserted.CountryCode)
FROM inserted
WHERE Location.Id = inserted.Id
END
ELSE
BEGIN
UPDATE Location
-- possible to perform an update without listing the columns?
END
END