----entity integrity, referential integrity, and related interpretations of the database

Source: Internet
Author: User
Tags one table

I. Entity integrity:

candidate Key : unique, allow not to fill

primary key : Unique, required, sort each table can have only one primary key.

Self-growth : must be a number. The system grows automatically.

Default value : If you do not fill in the default values are populated, if filled with the filled values are saved.

non-null constraint : cannot be filled .

Second, referential integrity:

foreign keys : At least two tables, typically two tables (main table, from table)

Main Table : A table used to constrain others

from table : constrained tables

The Master-slave table is only meaningful for the specified two tables.

Third, knowledge Interpretation:

1, what is the primary key, foreign key:

a record in a relational database has several attributes that can be a primary key if one of the attribute groups (note Group) can uniquely identify a record.
For example:
Student Form (school number, name, gender, Class)
Each student's school number is unique, the study number is a primary key
Curriculum (Course number, course name, credits)
where the course number is unique, the course number is a primary key
Score Table (School number, course number, grade)
A single attribute in the score table cannot uniquely identify a record, and the combination of the study number and course number uniquely identifies a record, so the attribute group for the study number and course number is a primary key.
the number of transcripts is not the primary key of the transcript, but it and the student table in the corresponding number, and the student list is the student table is the primary key, then said the score table is the student table of the foreign key
The course number in the results table is the foreign key of the curriculum.
defining primary and foreign keys is primarily to maintain the integrity of the relational database, summarizing:
(1) A primary key is a unique identifier that can determine a record, for example, a record includes a primary key for the ID number.
(2) A foreign key is used to associate with another table. is a field that determines the record of another table, which is used to maintain data consistency.
For example, a field in a table is the primary key of table B, so he can be a foreign key.
2. Differences between primary key, foreign key, and index
What is the difference between a primary key, a foreign key, and an index?
primary key foreign key index
Definition: Uniquely identifies a record, cannot duplicate, does not allow the foreign key to be an empty table is the primary key of another table, the foreign key can have duplicate, can be null value The field does not have duplicate values, but can have a null value
role: Used to ensure data integrity is used to establish contact with other tables is to improve the speed of query sorting
number: A primary key can have only one table and multiple foreign keys a table can have multiple unique indexes

3, what is the candidate key?

candidate keys are attributes that do not allow duplicate values , such as a student table, a school number, an ID number, and so on, then there are 2 candidate keys:
(identification number), but a table can have only one primary key (master code) and multiple candidate keys.

----entity integrity, referential integrity, and related interpretations of the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.