【问题标题】:SQL Server change column value on insert triggerSQL Server 在插入触发器上更改列值
【发布时间】:2014-10-09 05:20:42
【问题描述】:

如何在插入触发器中更改列的值?在 Oracle 中,我可以使用以下代码将 INSERT Trigger 中的 col1 值更改为大写。我如何在 SQL Server 中做到这一点?

IF exists (select col1 from inserted where col1 is  NOT NULL )
        begin 
            :NEW.col1:= UPPER(:NEW.col1);
        end 

【问题讨论】:

标签: sql-server oracle triggers


【解决方案1】:

这是使用 INSTEAD OF 触发器的一种方法。

CREATE TRIGGER MyTrigger ON MyTable INSTEAD OF INSERT AS
    INSERT MyTable(col1, [other columns])
    SELECT UPPER(i.col1)
        , i.[other columns]
    FROM Inserted i

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 1970-01-01
    • 2013-11-09
    相关资源
    最近更新 更多