Database Summary - key

Define primary and foreign keys mainly in order to maintain the integrity of the relational database, to sum up:
1. The 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.
 
2. A foreign key to another table is associated with. 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.

 

Example: Student Information (Student ID ID number Gender Age Height Weight hostel number) and information dormitory (Dormitory Building No.)

Super Key: set if it contains "study" or "ID number" two attributes called super key, e.g. R1 (student number sex), R2 (ID number height), R3 (student number ID number) or the like and so it can be called a super key!

Candidate key: do not contain extra super key attributes, such as (school), (ID number) are the candidate keys, such as R1 and a secondary school No. This attribute can uniquely identify a tuple, but there is no sex in this property has no effect on whether that uniquely identifies the tuple!

Primary key: is that users choose from a number of candidate key out of a key is the primary key, for example, you ask student number is the primary key, then the ID number can not be a primary key!

Foreign key: No. dormitory is a foreign key student information table.

Published 16 original articles · won praise 6 · views 973

Guess you like

Origin blog.csdn.net/wmj20001225/article/details/100824196