MySQL Learning-sql constraints

Source: Internet
Author: User
Constraint classification
  • Primary key: PRIMARY key
    Used to uniquely identify a row in a table and cannot be duplicated. e.g.:id INT(10) PRIMARY KEY
  • Defaults: Default
    When inserted, the value specified by default if no value is specified for the column. e.g.:age INT(10) DEFAULT10
  • Unique: Unique
    A specified column in a table, no duplicate values can be
  • FOREIGN key: FOREIGN key
    Maintain the integrity of the table and reflect the relationships in the table. A table can have more than one foreign key, each foreign key must references (reference) the primary key of another table, the value of the column that is constrained by the foreign key, and must have a corresponding value in its referenced column
  • Non-empty: NOT NULL
    In MySQL, inserting data violates a non-null constraint and only gives a warning, but executes successfully
To add a constraint to a column in a table

To add a constraint when a table is built:<列名> 类型(长度) <约束>

MySQL Learning-sql constraints

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.