How to distinguish between primary and foreign keys

This Article:
do comparison with other databases in the back when this was one of the points (relational database)
to figure out the difference between a paper on the line, into the company it is no problem.

This article addresses the problem:
disputes ①, primary keys and foreign keys

Let's look at the source of the primary keys and foreign keys bar:
1, primary key constraint (a PRIMARY KEY):
Ⅰ, each record uniquely identifies the database tables;
Ⅱ, primary keys must contain unique values;
Ⅲ, the primary key column can not contain a NULL value ;
IV, each table should have a primary key, and each table can have only one primary key. (PRIMARY KEY has auto-defined constraint UNIQUE

2, foreign key (FOREIGN KEY):
a foreign key table is the primary key of another table, the two relationship tables is formed.
Foreign key values rule: primary key or a null reference.
(1) When inserting non-null value, if this is not the primary key table value, it can not be inserted.
(2) update the value of the key can not be changed mainly not in the table.
(3) When you delete a table's primary key record, you can record the selected foreign key in the foreign key with built cascade delete or refuse to delete.
(4) update the master key record, and updates the same rejection cascade selection performed.

3, the role of the mysql database primary key and foreign key:
--------> Briefly, the SQL primary and foreign keys of the table is the tie function.
A primary key is to uniquely identify a record can be determined, for example, including a record number of positive identity, name, age. ID number is the only way to determine who you are, and others may have repeated, so, ID number is the primary key.
Associated with a foreign key in another table. It is able to determine the field of another table records, for maintaining data consistency.
For example, a field in the table A, table B is the primary key, then he may be a foreign key A of table.

Guess you like

Origin www.cnblogs.com/miniSimple/p/12275861.html