How to use alter table statement to modify table structure in MySQL database
This article will explain in detail how to use the alter table statement to modify the table structure in the MySQL database. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
As we all know, MySQL databases are often combined with PHP to develop powerful applications. So for those of us who are new to PHP programming, it is necessary to understand some simple operations of MySQL databases. The following editor will explain how the MySQL database uses the alter table statement to modify the table structure.
How to use alter table statement to modify table structure in MySQL database
1. Add column
Altertabletbl_nameaddcol_nametype
For example, add a column of weight to pet's table
Mysql > altertablepetaddweightint
two。 Delete column
Altertabletbl_namedropcol_name
For example, delete the column weight in the pet table
Mysql > altertablepetdropweight
How to use alter table statement to modify table structure in MySQL database
3. Change column
It is divided into changing the properties of the column and changing the name of the column.
Change the properties of the column-method 1:
Altertabletbl_namemodifycol_nametype
For example, change the type of weight
Mysql > altertablepetmodifyweightvarchar (30)
Change the properties of the column-method 2:
Altertabletbl_namechangeold_col_namecol_nametype
For example, change the type of weight
Altertablepetchangeweightweightvarchar (30)
Change the name of the column:
Altertabletbl_namechangeold_col_namecol_name
For example, change the name of weight in the pet table:
Mysql > altertablepetchangeweightwei
4. Change the name of the watch
Altertabletbl_namerenamenew_tbl
For example, rename the pet table to animal
Mysql > altertablepetrenameanimal; on "MySQL database how to use alter table statements to modify the table structure" this article shares here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.