Home > Database > Mysql Tutorial > body text

What keyword can be used instead of MODIFY to modify columns of a MySQL table?

PHPz
Release: 2023-09-03 17:21:11
forward
1382 people have browsed it

可以使用什么关键字代替 MODIFY 来修改 MySQL 表的列?

We can use the keyword CHANGE to modify the columns of an existing table. Using the CHANGE keyword we can change the name of a column and its definition. Its syntax is somewhat different from that of ALTER TABLE with the MODIFY keyword.

Syntax

Alter table table_name CHANGE old_columnname1 new_columnname1 datatype, CHANGE old_columnname2 new_columnname2 datatype… CHANGE old_columnnameN new_columnname datatype);
Copy after login

Example

In the following example, the name and size of the "City" and "RollNo" columns are modified with the help of the CHANGE keyword in the ALTER command .

mysql> Alter table Student CHANGE Rollno Id int, CHANGE City Place Varchar(10);
Query OK, 5 rows affected (0.40 sec)
Records: 5 Duplicates: 0 Warnings: 0
Copy after login

But if we only want to resize the column using the CHANGE keyword, then write the old column name twice along with the new size after the keyword CHANGE. The following example gives the description

mysql> Alter table Student CHANGE Email Email Varchar(30);
Query OK, 5 rows affected (0.33 sec)
Records: 5 Duplicates: 0 Warnings: 0
Copy after login

The above is the detailed content of What keyword can be used instead of MODIFY to modify columns of a MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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