更新触发器后的 SQL Server [英] SQL Server after update trigger
本文介绍了更新触发器后的 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个触发器有问题.我希望它更新请求的信息仅针对有问题的行(我刚刚更新的行)而不是整个表.
I have a problem with this trigger. I would like it to update the requested information only to the row in question (the one I just updated) and not the entire table.
CREATE TRIGGER [dbo].[after_update]
ON [dbo].[MYTABLE]
AFTER UPDATE
AS
BEGIN
UPDATE MYTABLE
SET mytable.CHANGED_ON = GETDATE(),
CHANGED_BY=USER_NAME(USER_ID())
如何告诉触发器这仅适用于相关行?
How do I tell the trigger that this applies only to the row in question?
推荐答案
这是我测试后的例子
CREATE TRIGGER [dbo].UpdateTasadoresName
ON [dbo].Tasadores
FOR UPDATE
AS
UPDATE Tasadores
SET NombreCompleto = RTRIM( Tasadores.Nombre + ' ' + isnull(Tasadores.ApellidoPaterno,'') + ' ' + isnull(Tasadores.ApellidoMaterno,'') )
FROM Tasadores
INNER JOIN INSERTED i ON Tasadores.id = i.id
插入的特殊表将包含来自更新记录的信息.
The inserted special table will have the information from the updated record.
这篇关于更新触发器后的 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文