Home  >  Article  >  Database  >  Detailed explanation on the use of alter command in mysql

Detailed explanation on the use of alter command in mysql

黄舟
黄舟Original
2017-08-20 15:06:301863browse

This article mainly introduces the MySQL knowledge points of the second-level computer examination in detail, and introduces in detail the use of the alter command in mysql. It has certain reference value. Interested friends can refer to it

The usage of alter command in mysql is used to edit the table structure. The specific content is as follows

Modify field type


mysql> alter table employee change depno depno int(5) not null;

Add index


mysql> alter table 表名 add index 索引名 (字段名1[,字段名2 …]);

Example:


mysql> alter table employee add index emp_name (name);

Add the index of the primary keyword


##

mysql> alter table 表名 add primary key (字段名);

Example:


mysql> alter table employee add primary key(id);

Index with unique restrictions


mysql> alter table 表名 add unique 索引名 (字段名);

Example:


mysql> alter table employee add unique emp_name2(cardnumber);

View the index of a table


mysql> show index from 表名;

Example:


mysql> show index from employee;

Delete an index


mysql> alter table 表名 drop index 索引名;

Example:


mysql>alter table employee drop index emp_name;

Modify table: add field:

##

mysql> ALTER TABLE table_name ADD field_name field_type;

View table:

mysql> SELECT * FROM table_name;

Modify the original field name and type:

mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;

Delete field:

ALTER TABLE table_name DROP field_name

The above is the detailed content of Detailed explanation on the use of alter command in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn