Click here to Skip to main content
15,887,975 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I got this 2 question incorrect on sql.

What I have tried:

Refer to the CUSTOMER and INVOICE relations (tables). Each customer could have many invoices or no invoices at all. Each invoice is linked to one and only one customer. CUS_CODE is the foreign key in the INVOICE table.

Assume that these are the only two tables in your database right now. Suppose you had to drop both the tables.

My answer was You will drop the Customer table first and then the Invoice table.

I do not the answer yet, once again not sure how I can attach the picture, not sure if i have to drop the invoce table first, or the customer table,

or not sure if this drop simultanious. Can someone explain
Posted
Updated 21-Nov-21 20:36pm
Comments
phil.o 22-Nov-21 1:41am    
Think about it: what happens if you delete a table which is referenced by another?

1 solution

Think about it: if you have one customer and many invoices, then the invoices must refer to the customer, not the other way round - or you would need an unknown number of columns in the customer table to refer to each separate invoice. For customer A it might be 1 invoice, for customer B it might be 100 - and you would need to know at the time you designed the tables!

So the Invoice references the Customer, not the other way around - one column in the invoice table can cope with any number of invoices for the same customer.
Is it physically possible to delete two tables "simultaneously"? Can you tear all the pages out of two hardback books at the same time in the real world? No - of course you can't - you would run out of hands just processing the first one! And databases are remarkably similar to real-world books: a book is a table, a series of books is a database, a row is a page ... so you can't delete two tables at the same time either - because one thread can only do one things at a time, and multiple threads won't necessarily run at the same time (multithreading gets complicated, so just take my word for that for the moment).

What happens to your data integrity if you drop the customer table first? Where do the invoice table references go now?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900