Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    10

    Unanswered: cancel the 'triggering' operation

    hello
    how can i cancel the operation that triggered.. a trigger in some cases?
    say i have an after insert trigger for a Students(id int, name varchar(15)) table and if i try to insert a student with an empty name i want the trigger to raise an error and cancel the insert operation.
    thank you

  2. #2
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    On this page:
    CREATE TRIGGER (Transact-SQL)

    you have this example:
    USE AdventureWorks;
    GO
    IF OBJECT_ID ('Sales.reminder1', 'TR') IS NOT NULL
    DROP TRIGGER Sales.reminder1;
    GO
    CREATE TRIGGER reminder1
    ON Sales.Customer
    AFTER INSERT, UPDATE
    AS RAISERROR ('Notify Customer Relations', 16, 10);
    GO


    and the explanation is:
    "The following DML trigger prints a message to the client when anyone tries to add or change data in the Customer table."
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

Posting Permissions

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