Home  >  Article  >  Database  >  What keyword can be used instead of MODIFY to modify columns of a MySQL table?

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

PHPz
PHPzforward
2023-09-03 17:21:111379browse

可以使用什么关键字代替 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);

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

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete