Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2013
    Posts
    6

    Unanswered: how to create a trigger?

    Hello,

    I want to create a trigger for the following table :

    [img=http://s24.postimg.org/89cniwszl/1234.jpg]

    This is my code :

    CREATE TABLE INVOICE (
    Invoice_id number CONSTRAINT Invoice_id_pk PRIMARY KEY,
    Invoice_date datetime NOT NULL DEFAULT CURDATE(),
    Invoice_location varchar2(150) NOT NULL,
    Invoice_order number CONSTRAINT Invoice_order_fk REFERENCES order_header(Order_id)
    );

    What would be the syntax for a trigger for the above table?
    I would really appreciate any help

    thnx!

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >how to create a trigger?
    use any text editor that you know how to use.

    Do I get to decide what the trigger does?

    Ask Tom Home contains many fine coding examples.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Apr 2013
    Posts
    6
    Quote Originally Posted by anacedent View Post
    >how to create a trigger?
    use any text editor that you know how to use.

    Do I get to decide what the trigger does?

    Ask Tom Home contains many fine coding examples.
    Trigger sets the new value for invoice_id attribute. How can i implement this?

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >Trigger sets the new value for invoice_id attribute. How can i implement this?
    I & most folks would utilize a SEQUENCE to establish the new value.

    GOOGLE is your friend!
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Apr 2013
    Posts
    6
    Quote Originally Posted by anacedent View Post
    >Trigger sets the new value for invoice_id attribute. How can i implement this?
    I & most folks would utilize a SEQUENCE to establish the new value.

    GOOGLE is your friend!
    Using SEQUENCE would have been better but in this case am supposed to use a trigger.

    CREATE TRIGGER increment_invoice_id
    BEFORE UPDATE OF invoice_id ON invoice
    BEGIN
    :new.invoice_id := ( : old.invoice_id + 1);
    END;
    /

    Will this trigger work?

  6. #6
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >Will this trigger work?
    since posted SQL throws syntax error, I know it won't work.

    In multi-user environment, what prevents two folks from obtaining same ld value before COMMIT?

    BTW, you can use SEQUENCE inside a TRIGGER.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  7. #7
    Join Date
    Apr 2013
    Posts
    6
    Quote Originally Posted by anacedent View Post
    >Will this trigger work?
    since posted SQL throws syntax error, I know it won't work.

    In multi-user environment, what prevents two folks from obtaining same ld value before COMMIT?

    BTW, you can use SEQUENCE inside a TRIGGER.
    I am not familiar with triggers. can you write a example regarding above table?

  8. #8
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >I am not familiar with triggers. can you write a example regarding above table?
    It is time for you to become familiar with triggers.
    BTW - We don't do homework here.
    You are off to a decent start.

    GOOGLE is your friend; but only when you actually use it.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  9. #9
    Join Date
    Apr 2013
    Posts
    6
    Quote Originally Posted by anacedent View Post
    >I am not familiar with triggers. can you write a example regarding above table?
    It is time for you to become familiar with triggers.
    BTW - We don't do homework here.
    You are off to a decent start.

    GOOGLE is your friend; but only when you actually use it.
    Well I am trying to learn and do it myself but I am stuck.
    Lets say we dont need to worry about multi-user environment, will my trigger work in that case?

  10. #10
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >will my trigger work in that case?
    What results when you compile the trigger?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  11. #11
    Join Date
    Apr 2013
    Posts
    6
    Quote Originally Posted by anacedent View Post
    >will my trigger work in that case?
    What results when you compile the trigger?
    After googleing a bit, I managed to get it work. thanks for your responses.

Posting Permissions

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