更新时间:2023-02-03 20:14:03
假设你有一个主键列,id
,(你应该有一个主键),加入插入
表(使触发器能够处理多行):
Assuming you have a primary key column, id
, (and you should have a primary key), join to the inserted
table (making the trigger capable of handling multiple rows):
CREATE TRIGGER tUpdateColB
ON products
FOR INSERT, UPDATE AS
BEGIN
UPDATE table
SET t.columnB = i.columnA
FROM table t INNER JOIN inserted i ON t.id = i.id
END
但如果 ColumnB 始终是 ColumnA 的副本,为什么不创建一个 计算列 代替?
But if ColumnB is always a copy of ColumnA, why not create a Computed column instead?