我的情况是,我在一个表中有 10 列。我从程序中插入 5 列,对于 5 列,我想创建一个触发器。是否可以?如果是,我该怎么做?
col1 col2 col3 col4 col5 col6 col7 col8 col9 col10
CREATE TRIGGER Fill_Trigger
ON DB
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
DECLARE @COL6 INT
DECLARE @COL7 INT -- and so on.
SET @COL6 = (SELECT COL1 FROM inserted) * (SELECT COL2 FROM inserted)
SET @COL7 = (SELECT COL3 FROM inserted) * (SELECT COL4 FROM inserted)
--Is it possible to do the following?
UPDATE inserted SET COL6 = @COL6
UPDATE inserted SET COL7 = @COL7
END
GO