开发者

How to select dynamically column from the table?

I wrote a trigger fo开发者_如何学Gor a table for insert ,update. For every insert and update, in the trigger I am comparing rows from 'Inserted' table and rows from 'Deleted' table.

I need to get the affected column. How to do this?

A B C D
1 2 3 5.

I am updating B's value with 3. Then the trigger will fire. In that trigger, from deleted table I can get :

A B C D
1 2 3 5

From the Inserted table I can get:

A B C D
1 3 3 5

I need to get the column B alone.

How to do this?

Thanks.


You can check whether or not a column has changed by IF UPDATE(namehere)

CREATE TRIGGER [dbo].[Triggername]
ON [dbo].[TableName]
FOR UPDATE
AS 

IF UPDATE(Columname) --If this column has changed
BEGIN
       --Your code here
    END
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜