SQL Server : trigger how to read value for Insert, Update, Delete

后端 未结 3 2054
予麋鹿
予麋鹿 2021-02-04 01:25

I have the trigger in one table and would like to read UserId value when a row is inserted, updated or deleted. How to do that? The code below does not work, I get

3条回答
  •  渐次进展
    2021-02-04 02:12

    Here is the syntax to create a trigger:

    CREATE TRIGGER trigger_name
    ON { table | view }
    [ WITH ENCRYPTION ]
    {
        { { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
            [ WITH APPEND ]
            [ NOT FOR REPLICATION ]
            AS
            [ { IF UPDATE ( column )
                [ { AND | OR } UPDATE ( column ) ]
                    [ ...n ]
            | IF ( COLUMNS_UPDATED ( ) { bitwise_operator } updated_bitmask )
                    { comparison_operator } column_bitmask [ ...n ]
            } ]
            sql_statement [ ...n ]
        }
    } 
    

    If you want to use On Update you only can do it with the IF UPDATE ( column ) section. That's not possible to do what you are asking.

提交回复
热议问题