MySQL in constraints

Source: Internet
Author: User

Constraints

What is constraint?

constraint is a "provision" that requires data to meet what conditions .

There are several constraints:

PRIMARY KEY constraint: form: primary key ( field name );

meaning (function): The value of the setting field can be used to "uniquely determine a row of data", in fact, the meaning of "primary key".

Unique constraint: form: Unique key ( field name );

meaning (function): Make the value of the Set field "Unique", naturally also distinguishable.

FOREIGN KEY constraint: form: foreign key ( field name ) references Other table names ( corresponding to field names in other tables );

Meaning (function): The value of the Set field must already be in the corresponding field in the corresponding table to which it is determined.

non-null constraint: form: NOT NULL is actually the "notnull" attribute thatwas written when a field was set.

This constraint can only be written on the field property;

Default constraints: form: default XX value; In fact, the default Value property that is written when you set a field

This constraint can only be written on the field property;

CHECK constraints: form: check(some kind of judgment statement), such as:

CREATE TABLE Tab1 (

Age tinyint,

Check (age>=0 and age <100)/* This is the checking constraint * /

)

In fact, primary KEY constraints, unique constraints, foreign key constraints, are just " 2 different angles of the same thing", they are also known as "PRIMARY key index", "Unique index", "Foreign Key Index".

MySQL in 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.