MySQL Basic Learning-sql constraints

Source: Internet
Author: User

1. PRIMARY KEY constraint (PRIMARY key)

The primary key (PRIMARY key) is used to constrain a row in the table, and as a unique identifier for the row, the primary key is the key to the exact row in one table. The primary key cannot be duplicated and cannot be empty.

A table can have only one primary key, either a primary key for a single field or a federated primary key for multiple fields, depending on the actual scenario.

2. FOREIGN KEY constraints

The foreign key (FOREIGN key) ensures both data integrity and the relationship between tables. A table can have multiple foreign keys, and each foreign key must REFERENCES (reference) The primary key of another table, the column that is constrained by the foreign key, and the value must have a corresponding value in the column it references.

Note that when there is a foreign key constraint, deleting the data is cumbersome, you need to first delete the table data of the associated foreign key, and then delete the table.

3. Non-null constraints

A non-null constraint (NOT NULL), which can be understood by a name, is a non-null constrained column that must not be empty when inserting a value.

4. Default Constraints

The default value constraint, default, specifies that when a column with a default constraint is blank, the Insert data is empty, and the defaults are used.

5. Unique constraints

A unique constraint is simple, which specifies that the value of a column specified in a table must not have duplicate values, that is, each value in this column is unique.

Add a point of knowledge:

Data type of SQL

Http://www.w3school.com.cn/sql/sql_datatypes.asp

Http://www.cnblogs.com/ray-wong/p/3792515.html

MySQL Basic Learning-sql constraints

Related Article

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.