Add primary key and foreign key

Source: Internet
Author: User

Table (i)Student (student table )

Add PRIMARY KEY constraint number Sno

Table (ii) Course (curriculum)

Add a PRIMARY KEY constraint course number con, add foreign KEY constraint faculty number ton

Table (iii) score (score table)

Add two foreign KEY constraint number Sno and course number Cno, the PRIMARY KEY constraint is sno+ Cno.

Table (iv) Teacher (Teacher's table)

Add PRIMARY KEY constraint faculty number TNO

PRIMARY KEY constraint:

1. The primary KEY constraint contains a non-null constraint with a unique constraint, only one;

2. A single row of data can be determined by the primary key column;

3. Automatically generate index according to primary key column, improve data retrieval efficiency;

4. Ensure that the uniqueness of the data is also normative.

CHECK constraints: Qualify the size and list by checking the rule statements.

FOREIGN KEY constraints:

1. The linkage between two tables is also a constraint relationship between two tables;

2. Settings: Set this field foreign key, must be associated to other tables with unique constraints on the fields, the general setting of the foreign key is the primary key on the table to be associated. Field names can be distinct, but data types are the same;

3. Ensure data integrity: when adding or modifying the foreign key field contents of the Foreign key table, the content must exist in the corresponding field in the primary key table. That is, to change the foreign key must first of its associated with a unique constraint field to get rid of;

4. When you modify the contents of the key in the primary key table, the fields in the Foreign key table are deleted first.

Add primary key and foreign key

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.