How to create a before insert trigger with message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ozchadl
    New Member
    • Apr 2010
    • 26

    #1

    How to create a before insert trigger with message

    I am trying to create a before insert trigger for a table called "bookorder"

    Table - "bookorder"
    'order_id' contains numbers
    'book' contains numbers
    'description' contains text

    The trigger is for when there is a duplicate of order_id and book.
    If duplicate of both order_id and book then error message says "Error Duplicate order_id X Book Y"
    eg the error message would say "Error Duplicate Order_id 1 Book 2"

    If no error then message says "Record added"


    Thanks for you help
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    wouldn’t a simple test before the db update suffice (i.e. try a select, if that returns something, don’t do the insert)

    Comment

    • ozchadl
      New Member
      • Apr 2010
      • 26

      #3
      I want it done by a create trigger before event.
      It is so that when new data is entered you get the error message if there is a duplicate, and a message saying that the data has been added.

      This is for a mysql database.

      Thanks for your help

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I’m not sure, if a trigger can do that. though I’m not a SQL expert.

        Comment

        • ozchadl
          New Member
          • Apr 2010
          • 26

          #5
          Originally posted by ozchadl
          I want it done by a create trigger before event.
          It is so that when new data is entered you get the error message if there is a duplicate, and a message saying that the data has been added.

          This is for a mysql database.

          Thanks for your help
          I have been told that a trigger can do thant.

          Thanks for your help

          Comment

          Working...