Home >Database >Mysql Tutorial >Detailed explanation on the use of alter command in mysql
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;
mysql> SELECT * FROM table_name;
mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
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!