What are MySQL Restrictions

Emphasis
1: restriction

Role: A set of mechanisms implemented to ensure data integrity using specific tools (constraints) according to different databases;

Here mainly explains MySQL limitations:

1. Non-empty constraints: Not null;

Indicates that a column cannot store null values

2, unique limitation: unique (); UK

The unique constraints must be unique, with the exception of zero;

3, primary key constraint: primary key (); pk

Primary key constraint = non-null + unique, make sure that a column (or two columns of multiple columns) has unique identifiers to make it easier to find a particular record in the table.

4, foreign key constraint: foreign key () references, FK

Make sure that data in one table matches the reference integrity of the value in another table. Syntax: CONSTRAINT FK_DEPT_ID foreign key (de pept_id) references Dept (dept_id);

5, self-incremental restriction: Auto_increment

6, standard restriction: standard

Specify a default value

7, Check the restriction: check

The value in the guaranteed column meets the specified conditions.

Example:

1
2
3
4
5
6
7
8
9
create table member (
id int (10),
phone int (15) unsigned zerofill,
name varchar (30) not null,
constraint uk_name unique (name),
constraint pk_id primary key (id),
CONSTRINT FK_DEPT_ID foreign key (Dealt_ID, field 2)
references de pept (topics table 1) (de pt_id)
);
Note:

// CONSTRAINT UK_NAME can be omitted. Uk_name Unique restriction name;

// pk_id primary key constraint name;

// FK_Dept_ID foreign key constraint name

2: index.

Role: Find specific data quickly, improve query results efficiency, ensure data uniqueness, find specific data quickly. Can speed up the connection between the tables and tables, implement the reference integrity between the tables and when retrieving the packages and sorting sorting, can greatly reduce the full-text search field of packages and sorting.

Index category:

1, primary key index (primary key);

2, unique index;

3, routine index (index);

4, full text index;

Summary: the caveat is to ensure the integrity of the table data and the index is to improve query efficiency and the two functions are different! Second, the guy is different.