We know that,MySQLDatabases are often combined with PHP to develop powerful applications. So for those who are new to PHP programming, it is necessary to understand some simple MySQL database operations. In this article, we useAlter tableStatement to modify the table structure. Next let's take a look at this part.
1. Add Columns
Alter table tbl_name add col_name type
For example, add a weight column to the pet table,
Mysql> alter table pet add weight int;
2. Delete Columns
Alter table tbl_name drop col_name
For example, delete the weight column in the pet table.
Mysql> alter table pet drop weight;
3. Change Columns
It can be divided into changing column attributes and changing column names.
Change the attribute of a column -- Method 1:
Alter table tbl_name modify col_name type
For example, changing the weight type
Mysql> alter table pet modify weight varchar (30 );
Change the attribute of a column -- Method 2:
Alter table tbl_name change old_col_name col_name type
For example, changing the weight type
Alter table pet change weight varchar (30 );
Change the column Name:
Alter table tbl_name change old_col_name col_name
For example, change the weight name in the pet table:
Mysql> alter table pet change weight wei;
4. Change the table name
Alter table tbl_name rename new_tbl
For example, rename the pet table to animal
Mysql> alter table pet rename animal;
This article introduces how to change the table structure of the MySQL database alter table. Next, we will introduce some simple operation methods for the MySQL database. I hope this article will help you gain some benefits!