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: 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: how to assign the contents of a field to a variable
      ... > Columnist, SQL Server Professional ... > teh requirements of the trigger are to export an XML document to MSMQ ... > DECLARE @int_msmqqueue INT ... > DECLARE FieldCursor CURSOR ...
      (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: execute w/triggers returning 0 rows
      ... Apparently the return valuefrom executing SQL in SQL Server is/are 'side effects' of certain SQL commands. ... Activating a trigger during execution of a command, where body the trigger that contains any of these commands, results in more side-effects. ... testing the triggers using their ad hoc query tool that inserting a row ...
      (perl.dbi.users)