Figuring out who/what did the update

  • I have an update trigger on a table.  The update trigger inserts a row into another table -- the data in this table is the key of the item that was changed and the update date.  What I'd love to add to the table is who/what caused the update in the first place.  The updates are controlled by stored procedures, so the "caller" would be a stored procedure.  I looked in Books Online, and didn't see anything obvious that would help me.  Does anybody have a clever way of accomplishing this?  This is a SQL 2000 database, BTW.

    Thanks!

  • The SQL Server login for a connection can be determined from the system function

    SUSER_SNAME()

    Of course, if this is a multi-tier application where the application always connects using the same login, this will not help. In that case, the real user will need to be passed as parameter.

    From Books OnLine:

    Returns the login identification name from a user's security identification number (SID).

    Syntax

    SUSER_SNAME ( [ server_user_sid ] )

    Arguments

    server_user_sid

    Is the user security identification number. server_user_sid, which is optional, is varbinary(85). server_user_sid can be the security identification number of any Microsoft® SQL Server™ login or Microsoft Windows NT® user or group. If server_user_sid is not specified, information about the current user is returned.

    Return Types

    nvarchar(256)

    SQL = Scarcely Qualifies as a Language

  • Functions HOST_NAME ( ), System_User, Current_User could be useful as well.

    _____________
    Code for TallyGenerator

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

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