Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple Trigger problem SQL server 2005

Options
  • 30-11-2009 3:28pm
    #1
    Closed Accounts Posts: 11,631 ✭✭✭✭


    Hi guys. Im trying to write a simple T-SQL trigger in sql server 2005

    My db is called "company" My table is called "works_on" . Basically i need a trigger that uses raiserror when i try to do a Insert into the table. I assume the raiserror displays some type of message box, iv messed around for abit and cant get my syntax right

    Could anyone help me out here would be much appreciated


Comments

  • Registered Users Posts: 2,494 ✭✭✭kayos


    RAISERROR will not display a message box, it will return the error back to the calling application where you can deal with it how you see fit, think about it why would you pop up a message box on a server locked away in the depts of a data-center?

    Any way the code for the trigger would be along the lines of
    CREATE TRIGGER trWorks_On_InsteadofInsert ON  dbo.works_on INSTEAD OF INSERT 
    AS 
    BEGIN
       RAISERROR('Inserts not allowed',16,1);
       ROLLBACK TRAN;
       RETURN;
    END
    GO
    


  • Closed Accounts Posts: 11,631 ✭✭✭✭Hank Scorpio


    kayos wrote: »
    RAISERROR will not display a message box, it will return the error back to the calling application where you can deal with it how you see fit, think about it why would you pop up a message box on a server locked away in the depts of a data-center?

    Any way the code for the trigger would be along the lines of
    CREATE TRIGGER trWorks_On_InsteadofInsert ON  dbo.works_on INSTEAD OF INSERT 
    AS 
    BEGIN
       RAISERROR('Inserts not allowed',16,1);
       ROLLBACK TRAN;
       RETURN;
    END
    GO
    


    Thanks for this

    Edit; Working flawlessy, saved my bacon! thanks again


  • Registered Users Posts: 2,494 ✭✭✭kayos


    nuxxx wrote: »
    Thanks for this

    Just be sure that the severity and state params in the raiserror suit your needs. And be careful the wrong severity and your will take out SQL Server :).


Advertisement