Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    18

    Unanswered: Oracle attribute auto update help

    Hi all,

    I have two tables, Booking and Bill as below. I want the Bill table to have its Bill total attribute automatically updated when a Booking Record is added. Is this possible and if so how ? Thanks In advance, Greg.

    Booking
    BookingId
    CheckInDate
    CheckOutDate
    CostPerNight

    Bill
    BillId
    BookingId (FK)
    Bill Total (This will be days (from check in and out dates) * Cost per Night)

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    > Is this possible and if so how ?
    by using an after insert 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.

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    However, why do you want to maintain a total column that may get out of sync? If you need a total, simply

    select sum(a.CostPerNight * ((a.CheckOutDate - a.CheckInDate)+1)),b.billid
    from booking a, bill b
    where a.bookingid = b.bookingid;
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    I agree with Bill.

    Also, if you did use triggers, you would also need to handle updates and deletes of Booking.

Posting Permissions

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