Capture user info

  • I have added a column to a table (Userid) and am trying to capture the user id of the user inserting a row. Can someone please remind me how to do this?

    I thought that selecting system_user and updating the new column like this:

    update table

    set column = system_user

    where INSERTED.pk_id = table.pk_id

    However i get an error saying:

    The column prefix 'INSERTED' does not match with a table name or alias name used in the query.

    TIA

  • Are you doing this in a trigger? INSERTED is not available outside a trigger.


    Joseph

  • Hi Carl,

    quote:


    I have added a column to a table (Userid) and am trying to capture the user id of the user inserting a row. Can someone please remind me how to do this?

    I thought that selecting system_user and updating the new column like this:

    update table

    set column = system_user

    where INSERTED.pk_id = table.pk_id

    However i get an error saying:

    The column prefix 'INSERTED' does not match with a table name or alias name used in the query.


    speaking of an update trigger?

    
    
    SELECT
    ...
    FROM inserted ins

    for capturing the system user you can use SUSER_SNAME() as default value on your table.

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Table Inserted and Deleted are only available

    with trigger. IF u want to get info of user add recored u can add a column like username and put default (SUSER_SNAME) for that column .

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply