Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2004
    Posts
    7

    Unanswered: trigger involving 2 tables

    I have 2 tables BOOKING (booking_id, car_id) and CAR (car_id, car_availability). the field car_availability takes the value YES/NO. I want to create a trigger in oracle so that whenever I make an entry in the BOOKING table for car_id, that same car_id 's availability in the CAR table should be set to NO.
    Pls someone help me

  2. #2
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    136
    Hello!

    E.g. You can do something like this:


    CREATE OR REPLACE FORCE VIEW VIEW_BOOKING
    (BOOKING_ID, CAR_ID)
    AS
    SELECT
    BOOKING_ID
    , CAR_ID
    FROM BOOKING;




    CREATE OR REPLACE TRIGGER TRG_VIEW_BOOKING_INSTOF_INS
    INSTEAD OF INSERT ON VIEW_BOOKING
    DECLARE
    var NUMBER;
    BEGIN
    var := :NEW.CAR_ID;

    INSERT INTO BOOKING(BOOKING_ID, CAR_ID) VALUES(:NEW.BOOKING_ID, var);
    UPDATE CAR SET CAR_AVAILABILITY = 'NO' where CAR_ID = var;

    END;

    insert into VIEW_BOOKING( BOOKING_ID, CAR_ID) VALUES(1, 2);


    Regards,
    Julia
    Regards,
    Julia

Posting Permissions

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