what is a primary key and foreign key constraints?
Jarluk
2006-02-02 10:30:12 UTC
what is a primary key and foreign key constraints?
Three answers:
frankfazzio
2006-02-02 10:51:28 UTC
Let's pretend we have a customer table with all our customers and an invoice table with all the invoices we've generated. Each customer has a unique customer id, and every invoice has a unique invoice id PLUS has the id of the customer it belongs to.
A primary key is usually used to make sure you don't have two records in the same table with the same key value. If we had the same customer in our table twice, we might try to send them two bills, or do something twice. The primary key constraint of uniqueness will not allow us to insert a second customer in the table with the same id.
A foreign key is normally used to make sure the parent record IN ANOTHER TABLE exists. For example, it would not make sense to create an invoice with no customer to send it to. A foreign key constraint will not let you put a record in the invoice table unless the customer id on it exists in the customer table.
Popocatepetl
2006-02-02 10:52:28 UTC
Primary key is the column or the combination of columns on a table, that differentiates every record. The value on the column or the combination could never be equal for two diferent records.
Foreign Key Constraints is the constraint that defines the relation betwen two tables.
elwanda
2016-12-12 17:51:57 UTC
>> (definite i favor in elementary words one education in accordance to worker) If it truly is real, then splitting it into diverse tables would not scent excellent. you're including complexity the position it ought to no longer be necessary. (grinning's factor is valid, yet it truly is truly severe normalization that delivers even more beneficial complexity. appears like it isn't justified the following). what's your definition of too many columns? MySql enables 4096. Oracle 1000. Microsoft is 1024, or 30000 in case you really favor it. Are you really hitting those? if so, i believe there is something else incorrect the following. a million,000 columns for an worker would look more beneficial than sufficient.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Search results for 'what is a primary key and foreign key constraints?' (Questions and Answers)