插入时触发

时间:2012-08-24 20:24:06

标签: sql-server sql-server-2008 tsql

如何在插入时创建具有ROUND值的触发器?

此触发器不起作用:(

CREATE TRIGGER test
   ON repaymentevents
   AFTER INSERT
AS
BEGIN
    SELECT round(value, 2) FROM Inserted 
END

2 个答案:

答案 0 :(得分:1)

正如@marc_s所说,我认为你需要一个INSTEAD OF触发器:

CREATE TRIGGER test
   ON repaymentevents
   INSTEAD OF INSERT
AS
BEGIN
    INSERT INTO repaymentevents
    SELECT round(SomeValue, 2) FROM Inserted 
END

Here is an example.

答案 1 :(得分:0)

这是你需要的吗?这是空调,显然我无法测试,因为我没有你的桌子,但希望你能得到这个想法。

CREATE TRIGGER test
   ON repaymentevents
   AFTER INSERT
AS
BEGIN
    UPDATE repaymentevents 
     INNER
      JOIN INSERTED I
        ON I.id = repaymentevents.id
       SET value = round(i.value, 2)
END