Results 1 to 2 of 2

Thread: update trigger logic

  1. #1
    Join Date
    Nov 2002
    Posts
    261

    update trigger logic

    Posts: 20
    Joined: Aug 2003
    Mon November 08, 2004 9:42 AM



    I have a table where from 1 to 3 fields will be update (lastname,firstname,birthdate). Any combination of the 3 can be updated. I need a trigger to handle the updates which update some other db tables. I can handle the update trigger part, the ? is how to best approach the logic. I can do thee separate statements to handle an update for each of the columns, but that could cause 3 separate updates to fire. I was looking at doing something like

    If UPDATE(last_name)
    and UPDATE(first_name)
    and update(date_of_birth)
    BEGIN
    ...
    end
    else if
    If UPDATE(last_name)
    and UPDATE(first_name)
    begin
    ...
    end

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can use COLUMNS_UPDATED() function to find which column updated and build a case statement.

    It is listed in CREATE TRIGGER part of BOL.

Posting Permissions

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