触发器中的更新列在插入期间也起作用吗

问题描述 投票:0回答:2

我正在创建一个触发器,该触发器在插入或更新特定列时执行某些功能。我知道下面的内容适用于更新,但它也适用于插入吗?

IF UPDATE (MobilePhone)
BEGIN
SELECT  @TeamId = TeamId FROM Inserted
END
sql sql-server triggers
2个回答
1
投票

看起来您可以从 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.

0
投票

它在语法上可以工作,但它可能不会按照您想要的方式运行。对于 INSERT 语句,UPDATE(column) 函数始终返回 TRUE。来自文档:

IF UPDATE 在 INSERT 操作中返回 TRUE 值,因为列插入了显式值或隐式 (NULL) 值。

© www.soinside.com 2019 - 2024. All rights reserved.