Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    13

    Unanswered: Create Audit Trigger

    I need to create a simple audit trigger for a table with 12 columns. I need to determine which row was changed. Is there a simple way to do that. The table structure is
    ID Integer(4)
    barcode(25)
    epc_tag(24)
    bc_stop_flag(1)
    reject_flag(1)
    complete_flag(1)
    hold_flag(1)
    pe_1_flag
    pe_2_flag
    pe_3_flag
    pe_4_flag
    pe_5_flag

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Is there a defined primary key (possibly the ID column) or a unique index on the table?

    -PatP

  3. #3
    Join Date
    Aug 2004
    Posts
    13

    Primary Key

    The primary key is the ID column. Sorry.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Within the trigger, there are two views named inserted and deleted. These are the rows that caused SQL Server to launch your trigger. If you need to, you can use them to join back to your underlying table (usually only if you need to do an update based on logic in your trigger).

    It is pretty obvious how to handle INSERT and DELETE triggers, but it helps to know that SQL Server treats an UPDATE statement as a DELETE then an INSERT (so you find the "before" and "after" update images in the views).

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •