Home > Database > Mysql Tutorial > body text

How to modify column in mysql

WBOY
Release: 2022-05-19 17:47:35
Original
4505 people have browsed it

Method: 1. Use the "alter table table name modify column column name dateType" statement to modify the data type; 2. Use the "alter table table name change old column name new column name type (length)" statement to modify the name. .

How to modify column in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to modify column in mysql

1. Modify the data type of the field

 alter table table_name modify column column_name dateType
Copy after login

The example is as follows:

How to modify column in mysql

2. Modify the field name

alter table table_name change old_column_name new_column_name  int(11);
Copy after login

Expand knowledge:

1. Add a unique key

 alter table table_name add unique key `uniq_column` (`column`);
Copy after login

2. Add a field

alter table table_name add column column_name datatype
Copy after login

3. Delete a field

ALTER TABLE table_name DROP COLUMN column_name
Copy after login

4. Add a column

----alter table students add column 列名 列属性
alter table students 
    add column 语文 varchar(4) NOT NULL ;
Copy after login

----Add to the end of the column by default

after the name of the specified column name

First Add to the first column

Note: MySQL5.7.16 version does not seem to support Second, Third ...

# #
  alter table students 
    add column 数学 varchar(4) NOT NULL after 出生日期 ;
Copy after login

5. Delete columns

----alter table 表名 drop column 列名
alter table students drop column 成绩;
Copy after login

Recommended learning: mysql video tutorial

The above is the detailed content of How to modify column 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 [email protected]
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!