Insert/Update trigger

  • Hi,

      I have a trigger which runs on every insert and update of the table. I want to assign some value to the column in that table only if the record is getting inserted.

      In oracle I can check it by the following statement

      if (inserting) then

         do soming

      end if

     Is there anything in SQL SERVER to check if the trigger is inserting or updating the table?

     

    Kavita

     

  • if not exists (Select * from Deleted) and Exists (Select * from Inserted)

    begin

    Update...

    end

  • or just set a DEFAULT for that column.

    If it's being updated, it would be already there, and the default wouldn't do anything... if it's inserted, it would populate that column with a value.

    Unless you want a different value based on another column in the inserted row?  Not sure of defaults can handle this... I don't think so.

  • No, that would take a computed column or a trigger .

  • Thanks

    I have used " if not exists (Select * from Deleted) and Exists (Select * from Inserted)" and now trigger is running like a champ.

     

     

     

Viewing 5 posts - 1 through 4 (of 4 total)

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