Home  >  Article  >  Database  >  How to modify field attributes in mysql

How to modify field attributes in mysql

WBOY
WBOYOriginal
2022-01-05 11:24:5516438browse

In mysql, you can use the alter command to modify field attributes. This command is used to modify the data table name or modify the data table fields. The syntax is "alter table table name modify COLUMN field name new data type".

How to modify field attributes in mysql

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

How does mysql modify field attributes

mysql> alter table table name modify column field name type.

The city field of the address table in the database is varchar(30), and the modified type can be used (modify the type with caution, as it may cause errors in the original data).

mysql> alter table address modify column city char(30); can be used to modify the length (to modify the length, make sure it is not shorter than the existing data to ensure that the original data is correct) mysql> alter table address modify column city varchar(50);

How to modify field attributes in mysql

alter table table name modify column field name type; news The title field in the table originally had a length of 100 characters, and the current length needs to be changed to 130 characters.

How to modify field attributes in mysql

mysql Modify field type: alter table news modify column title text; I found that using this sql can also directly modify the original type of the field!

Usually It can be written as alter table table name modify column column name new column type. For example: the type of column sname in the student table is char(20), and now it needs to be modified to varchar(20). The SQL statement is as follows alter table student modify column sname varchar( 20);

How to modify field attributes in mysql

#Method to modify the column name and column data type at the same time: usually it can be written as alter table table name change column old column name new column name new column type student table The type of column sname is char(20), now it needs to be changed to stuname varchar(20) alter table student change column sname stuname varchar(20);

How to modify field attributes in mysql

Recommended learning: mysql video tutorial

The above is the detailed content of How to modify field attributes 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