|
-
Mar 30th, 2006, 11:50 AM
#1
Thread Starter
Junior Member
Deleting records that have relationships.
Hello
Can you tell me the best way to delete a record that is related to another table. For instance, I have a customer and invoice table (Customer ID is the Primary Key in Customer and the Foreign key in invoice).
I wish to delete the Customer in the Customer table but not all of its related invoices in the Invoice table.
I am using VB6 front end with an Access database.
Thanks
-
Mar 30th, 2006, 11:52 AM
#2
Re: Deleting records that have relationships.
How about simply flagging that customer as Not Active.
If you delete the customer, to what are all of their invoices now related?
-
Mar 30th, 2006, 02:23 PM
#3
Re: Deleting records that have relationships.
As a principle, I never want to delete records unless I really have to. As an alternative I always add a Deleted flag (a bit or boolean) to each table. Then when I need to 'delete' a record, I just set that flag to TRUE.
Then, all queries to the tables include a line in the WHERE clause that only returns records where Deleted=FALSE.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Mar 30th, 2006, 02:39 PM
#4
Re: Deleting records that have relationships.
Hack and DKenny are aboslutely correct. If you have the tables related using a FK relationship (Parent-Child) then you can not have a child with out a parent (the Old relationial rules rear there head here). You can mark a customer as deleted using a feild as DKenny suggests, my only point to that would be not to use a Boolean (Yes/No) data type (if you are using MS Access). If you move to larger type RDBMS they don't all support True/False datatypes (Oracle as an example), I normmaly use a Text type of 1 charactor (stores a null (nothing) or a Y for deleted).
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Mar 31st, 2006, 02:07 AM
#5
Thread Starter
Junior Member
Re: Deleting records that have relationships.
Thanks Hack, DKenny and Mazz1.
Your comments are very helpful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|