Results 1 to 5 of 5

Thread: Trigger for delete or specific update

  1. #1
    Join Date
    Nov 2002
    Posts
    261

    Trigger for delete or specific update

    I have a table where I want to prevent user from deleting or setting a flag on a field to "y" with a database trigger (sql 2000). I understand the trigger for just one (stopping the delete, or stopping the field being changed to "y"). Should I have 2 seperate triggers or would there be a way to handle both.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    One trigger can work for both, you just need to put the trigger fire condition as

    CREATE TRIGGER tg ON TABLE t1
    FOR UPDATE, DELETE
    AS
    ...

  3. #3
    Join Date
    Nov 2002
    Posts
    261
    That I get, it was trying to separate the login. If you are doing just a straight delete the trigger would be
    create trigger tg on table for delete.....

    In this cas trying to figure out logic for delete first and then for update. What would be the way to determine if the record was deleted? I know in triggers the records are referenced from deleted.name, or inserted.name

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    If get value in deleted but not in inserted, it's delete. Otherwise, is update.

  5. #5
    Join Date
    Nov 2002
    Posts
    261
    In short if @@rowcount from inserted = 0 then...........

Posting Permissions

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