Re: Audit Table

From: Tom Moreau (tom_at_dont.spam.me.cips.ca)
Date: 12/29/03

  • Next message: Yuan Shao: "RE: Audit Table"
    Date: Mon, 29 Dec 2003 05:32:41 -0500
    
    

    Front-end code typically has to influence on a trigger. The trigger fires
    as a result of the triggering action - INSERT, UPDATE or DELETE. Here's an
    example to do what you want:

    create trigger triu_MyTable on MyTable after insert, update
    as
    if @@ROWCOUNT = 0
        return

    update MyTable
    set
         LastModBy = CURRENT_USER
    , LastUpdateDateTime = CURRENT_TIMESTAMP
    where
        PK in (select PK from inserted)
    go

    -- 
       Tom
    ----------------------------------------------------
    Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
    SQL Server MVP
    Columnist, SQL Server Professional
    Toronto, ON   Canada
    www.pinnaclepublishing.com/sql
    .
    "Michelle" <michelle.vanden@eglin.af.mil> wrote in message
    news:034501c3cdc5$1a2f3a60$a401280a@phx.gbl...
    The current environment is an ASP frontend with IIS 5.0
    using (windows authentication) and SQL Server 2000(windows
    authentication) on the same machine.
    I would like to add two columns onto several tables and
    have a timestamp and username inserted into them when a
    user performs an update or insert.  I believe it's a good
    idea to use an insert or update trigger, but I'm not sure
    how the asp application delegates who is logged to sql
    server.
    What is the best way to do this?
    Do you need to have IIS and Sql server configured a
    certain way in order to grab the username from the asp
    application?
    

  • Next message: Yuan Shao: "RE: Audit Table"

    Relevant Pages

    • Re: Records not inserting...
      ... > I am totally new to SQL server. ... However, in a trigger, would I be ... test the effects of certain data modifications and to set conditions for ... UPDATE statements. ...
      (microsoft.public.sqlserver.odbc)
    • Re: Help for an Oracle Newbie
      ... application I wrote using SQL Server ported over to Oracle. ... Obviously there are several built in data types in SQL Server that do ... Of course I had to use a different name for the trigger under each ...
      (comp.databases.oracle.server)
    • Re: TRIGGER (AFTER INSERT) and Store Procedure ... insert failed !
      ... >into SQL server, the record exist anyway! ... >If you refresh the data you will see the record... ... it gets refreshed after trigger excecution automatically. ... I don't know your monitoring system, but I guess that removing the result ...
      (microsoft.public.sqlserver.programming)
    • Re: Access Bug with SQL Server identity columns
      ... Even though SQL Server since version 2000 has had a reliable ... The work-around I've always used is to make sure that no trigger inserts into ... a table that contains an IDENTITY column, and use some other unique identifier ... >create a form on table1 with a subform on table2. ...
      (comp.databases.ms-access)
    • Re: Help for an Oracle Newbie
      ... application I wrote using SQL Server ported over to Oracle. ... Obviously there are several built in data types in SQL Server that do ... Of course I had to use a different name for the trigger under each ... In SQL Server I always create a CreatedDate column ...
      (comp.databases.oracle.server)