Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2009

    Unanswered: deleting a foreign key

    i have to delete a record from a table with ids and names but on this is is a foreign key to another table how can i remove that record but still exist for a future use??

    actualy i have to delete a customer record this record include customer id and customer name but on this customerid (which is a foreign key to a flightbooking table) are reserved some bookings. the flightbooking include flightid , customerid , bookingid ,number of reserved seats and the status of the booking reserved , cancel or held

    any help????

  2. #2
    Join Date
    May 2007
    somewhere in dbforums
    Quote Originally Posted by emmapat
    i have to delete a customer record
    Is it that you want to delete the customer record but not his flight booking details???? Are you sure this would not introduce any inconsistency into the system bcoz in the future you wont have any customer details against that flight booking???? From what i get the db has not been defined for that....

    Not a solution
    Be sure you really really really really know what you are doing before you try this -
    Try the other way round... delete the records from flightbooking for that cust id and then delete the customer id.... coz the way i see it you cannot just delete the customer id without cleaning up all his details in flightbooking table...
    IBM Certified Database Associate, DB2 9 for LUW

  3. #3
    Join Date
    Dec 2008
    I agree with Nick that your description seems to leave orphaned flightbooking details.

    If you want to keep this information because it should be connected to a different customer: Insert the new customer info into the parent table, update foreign key in the flightbooking table to point to the new customer, then delete the original customer.

    Or just export the flightbooking info to a file to save it, delete the row in the flightbooking table, then delete the parent row. You will still have the info for future use.

    Hope one of the suggestions is useful to you.

Posting Permissions

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