If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > triggers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-02-04, 02:16
fahad fahad is offline
Registered User
 
Join Date: Apr 2004
Posts: 7
Question triggers

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.
Reply With Quote
  #2 (permalink)  
Old 04-02-04, 02:29
zeus77 zeus77 is offline
Registered User
 
Join Date: Mar 2004
Location: Venice,Italy
Posts: 20
try this:

create or replace trigger ins_booking after insert on booking
begin
update car
set car_availability='NO'
where car_id in (select car_id from :NEW);
END;
Reply With Quote
  #3 (permalink)  
Old 04-02-04, 05:17
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
I'm afraid your trigger won't compile, Zeus ...

But this one will
PHP Code:
CREATE OR REPLACE TRIGGER trg_a_i_booking
   AFTER INSERT
   ON booking
   
FOR EACH ROW
BEGIN
   UPDATE car
      SET car_availability 
'NO'
    
WHERE car_id = :NEW.car_id;
END
Reply With Quote
  #4 (permalink)  
Old 04-05-04, 10:26
fahad fahad is offline
Registered User
 
Join Date: Apr 2004
Posts: 7
trigger not running properly

trigger has been created successfully but it is not doing what i want it to do. when inserting into the booking table, it is giving an error saying :

ORA-02291: integrity constraint () violated -parent key found

how should i proceed????
pls help
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On