Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Posts
    2

    Unanswered: Triggers in MS SQL

    Hi all,
    Could anyone point me to a site that gives a basic tutorial on PL/SQL in MS SQL Server. I know nothing about the syntax, though I am slightly familiar with Oracle PL/SQL.

    My present problem is I need to terminate an insert based on an if condition. I have managed to RAISERROR. But the insert still goes through. Here's the block:

    CREATE TRIGGER PACKAGE_TRIGGER ON PACKAGES
    FOR INSERT AS
    DECLARE @LOWER NUMERIC
    DECLARE @UPPER NUMERIC
    SELECT @LOWER = Lower from Inserted
    SELECT @UPPER = Upper from Inserted
    IF @LOWER > @UPPER
    RAISERROR ('Message number lower limit greater than upper limit', 16, 1)


    Is there a more elegant way of doing this?


    Thanks in advance for the help.
    praveen.

  2. #2
    Join Date
    Nov 2003
    Posts
    3
    You can enforce this with a constraint which is probably simpler:

    e.g.

    ALTER TABLE TEST1
    ADD CONSTRAINT UPR_GRTR_LWR CHECK ([upper] > [lower])

  3. #3
    Join Date
    Nov 2003
    Posts
    2
    Thanks a lot for the suggestion. I didnt know you could have constraints like this.

    cheers
    praveen.

Posting Permissions

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