Home  >  Article  >  Database  >  How to modify column in mysql

How to modify column in mysql

WBOY
WBOYOriginal
2022-05-19 17:47:354748browse

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

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);

Expand knowledge:

1. Add a unique key

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

2. Add a field

alter table table_name add column column_name datatype

3. Delete a field

ALTER TABLE table_name DROP COLUMN column_name

4. Add a column

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

----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 出生日期 ;

5. Delete columns

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

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!

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