Home > Database > Mysql Tutorial > body text

Detailed explanation on the use of alter command in mysql

黄舟
Release: 2017-08-20 15:06:30
Original
1839 people have browsed it

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;
Copy after login

Add index


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

Example:


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

Add the index of the primary keyword


##

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

Example:


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

Index with unique restrictions


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

Example:


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

View the index of a table


mysql> show index from 表名;
Copy after login

Example:


mysql> show index from employee;
Copy after login

Delete an index


mysql> alter table 表名 drop index 索引名;
Copy after login

Example:


mysql>alter table employee drop index emp_name;
Copy after login

Modify table: add field:

##

mysql> ALTER TABLE table_name ADD field_name field_type;
Copy after login

View table:

mysql> SELECT * FROM table_name;
Copy after login

Modify the original field name and type:

mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
Copy after login

Delete field:

ALTER TABLE table_name DROP field_name
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!