尝试创建一个触发器,仅允许更新记录不到三天的记录

时间:2012-11-10 19:28:04

标签: sql sql-server-2008 tsql triggers

我尝试创建一个触发器来更新不到三天的记录 继承我的代码我执行表空白我认为错误是与dateadd函数 有什么建议吗?

 ALTER TRIGGER update_marketinglistC
    ON marketing_list FOR UPDATE
    AS
    BEGIN

        SELECT * FROM INSERTED 
        SELECT * FROM DELETED

        Select * from inserted 
        where DateCreated <= DATEADD(dd,-3,CURRENT_TIMESTAMP)



    END

1 个答案:

答案 0 :(得分:0)

试试这个。

Alter Trigger update_marketinglistC
On marketing_list For Update
As

Begin

    If exists (Select * from inserted 
               Where DateCreated <= DATEADD(dd, -3, current_Timestamp))
    Begin
        Rollback Transaction
        Raiserror('Cannot update records more than three days old.', 16, 1)
    End

End