Add a column at a specified position to the MySQL table
Alter table test add column id int unsigned not null auto_increment primary key first is a common operation to ADD columns to a TABLE, when adding a column in MySQL, you can specify the position of the column to add two keywords to the specified position: FIRST and AFTERFIRST indicate that adding the FIRST column "AFTER" indicates adding a column. Note that BEFORE is not used when MySQL adds a column to the specified position. You can use FIRST for the FIRST column, not AFTER for the FIRST column. Syntax:
Alter table table_name ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name]
Instance:
Drop table if exists 'test'; create table 'test' ('A' int (11) not null, 'B' varchar (200) NOT NULL) ENGINE = InnoDB default charset = utf8;
Add a column c after column a of table test:
Alter table test add column c int not null after
Add the field id in the first column of the test table:
Alter table test add column id int unsigned not null auto_increment PRIMARY KEY FIRST
The full text is complete.