开发者

SQL Trigger - Replace system user with custom field

I have a sql trigger that is used to audit my database ta开发者_开发百科bles. Data is changed via web interface. Only authenticated users can change/add data.

In the trigger I have a line of code that says

select @UserName = system_user

Instead of the system_user, I want UserId (of authenticated web user) to be assigned to @UserName. UserId is found in the table for every row as one of the columns.

What can I replace system_user with to get this effect. thanks in advance.


If it is SQL server, you can simply query from the "Inserted" table like below:

select @UserName =(select Your_USERID_ColumnName from inserted)

With SQL Server while inserts/updates and deletes happen there are two virtual tables "Inserted" and "Deleted" that you can query against

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜