Create index < index name > on < table name > (< column name > [<; Length >] [American DESC])
Limitation: Only ordinary indexes and unique indexes can be added; Cannot create primary key index.
Second, the method of changing the table.
Change table < table name > add index [<; Index name >] (<; Column name >, ...)
Change table < table name > add unique [index | key] [<; Index name >] (<; Column name >, ...)
Change table < table name > add primary key (< column name >, …)
Change table < table name > Add foreign key [<; Index name >] (<; Column name >, ...)
Third, when CREATE TABLE is specified.
Create a universal index
Create table tb_stu_info
(
Id INT is not empty.
Name CHAR(45) is empty by default.
Dept_id INT is empty by default.
Age INT defaults to NULL.
Height INT defaults to NULL,
Index (height)
);
Create a unique index
Mysql & gt creates table tb_stu_info2.
(
Id INT is not empty.
Name CHAR(45) is empty by default.
Dept_id INT is empty by default.
Age INT defaults to NULL.
Height INT defaults to NULL,
Unique index (height)
);
Create a primary key (although ALTER TABLE can also be created, the primary key is usually created when the table is created).
Create table mytable (
ID INT is not empty.
User name VARCHAR( 16) is not empty.
Primary key (ID)
);