Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2004
    Location
    Cergy
    Posts
    65

    Question Unanswered: Trigger to update another table

    I have an Order header table (ORDER_HEADER) and I want to update a lines table (ORDER_LINES), colum DATE via a trigger (when UPDATE or INSERT).

    What is the synthax ?


    Thanks

  2. #2
    Join Date
    Oct 2003
    Posts
    84
    What exactly do you want to do to the ORDER_LINE table? Try including some DDL for us to get an idea of both table structures.

  3. #3
    Join Date
    Jan 2004
    Location
    Cergy
    Posts
    65

    Arrow

    ORDER_HEADER table:
    NO_ORDER (num 8)
    ...

    ORDER_LINES table
    NO_ORDER (num 8)
    DATE_UPDATED (Date)
    ...

    When the table ORDER_HEADER is updated or inserted, I want to update the field DATE_UPDATE in the ORDER_LINES table.

  4. #4
    Join Date
    Sep 2003
    Posts
    522
    look up triggers in bol

  5. #5
    Join Date
    Oct 2003
    Posts
    84
    CREATE TRIGGER TRG_UpdateORDER_LINES ON ORDER_HEADER FOR INSERT AS
    BEGIN
    UPDATE ORDER_LINES SET
    DATE_UPDATED = GETDATE()
    WHERE NO_ORDER IN
    (SELECT NO_ORDER FROM Inserted)
    END

  6. #6
    Join Date
    Oct 2003
    Posts
    84
    On the first line where I said "FOR INSERT", replace it with "FOR UPDATE"

Posting Permissions

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