我正在创建一个触发器,该触发器在插入或更新特定列时执行某些功能。我知道下面的内容适用于更新,但它也适用于插入吗?
IF UPDATE (MobilePhone)
BEGIN
SELECT @TeamId = TeamId FROM Inserted
END
看起来您可以从 MSDN 文档中获取。
http://technet.microsoft.com/en-us/library/ms187326.aspx
Is the name of the column to test for either an INSERT or UPDATE action. Because the table name is specified in the ON clause of the trigger, do not include the table name before the column name. The column can be of any data type supported by SQL Server. However, computed columns cannot be used in this context.
它在语法上可以工作,但它可能不会按照您想要的方式运行。对于 INSERT 语句,UPDATE(column) 函数始终返回 TRUE。来自文档:
IF UPDATE 在 INSERT 操作中返回 TRUE 值,因为列插入了显式值或隐式 (NULL) 值。