wplecturer.com
0 votes
14 views

How does a foreign key help?
in General by | 14 views

1 Answer

0 votes

The FOREIGN KEY constraint is used to prevent actions that would destroy links between tables. A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table (google).

If you have the header Orders Table, then at the Detail Orders Table must exist the Primary Key of an order as foreign key in order to be a relation for the two tables. So we know what are the products of this order, the detal table includes one record per product ( if this producy has 3 products we may have quantity 3, but one row).

We can not delete the Header order if there are record(s) in the Detail Order, and we know this from Foreign Key ( of course we may use DELETE CASCADE).

I hope to help

by

1.6k questions

1.6k answers

81.6k users

5 Online Users
0 Member 5 Guest
Today Visits : 862
Yesterday Visits : 1257
Total Visits : 1892116
Dear All, These are my answers from Quora and primarily Google; please check the answer and from others sites; the answers are free and without any liability.To make a decision, write down all of the positives and negatives on a piece of paper.Thank you, Elias Katsaniotis, MSc.
1,644 questions
1,649 answers
81,587 users
@ 2022 V Katsanioti ,All rights reserved