Mysql statement to add a column is "ALTER TABLE", and the syntax is "ALTER TABLE table name ADD new column name data type [constraints] [FIRST];". The FIRST keyword is optional. If omitted, the column is added at the end of the table; if not omitted, the column is added at the beginning of the table.
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
MySQL data tables are composed of rows and columns. Usually the "columns" of the table are called fields (Field), and the "rows" of the table are called records (Record). As your business changes, you may need to add new fields (columns) to existing tables.
In mysql, the statement to add a column is "ALTER TABLE"; this statement can change the structure of the original table, such as adding or deleting columns, changing original columns Type, rename columns or tables, etc.
Add the syntax format of the column:
ALTER TABLE 表名 ADD 新列名 数据类型 [约束条件] [FIRST] ;
The description of the syntax format is as follows:
##Table name is the data table Name;
New column name is the name of the column (field) to be added;
data Type is the data type that can store data in the field to be added;
[Constraints] is optional and is used to perform operations on the added field. constraint.
[FIRST] is optional and is used to add columns at the beginning of the table; if omitted, the column will be added at the end of the table by default,
Example: We have a student data table, its table structure is like this
Use the ALTER TABLE statement Add an INT type field age at the endALTER TABLE student ADD age INT(4);
ALTER TABLE student ADD stuId INT(4) FIRST;
mysql video tutorial]
The above is the detailed content of What is the statement to add a column in mysql. For more information, please follow other related articles on the PHP Chinese website!