ALTER TABLE test ADD COLUMN ID INT UNSIGNED not NULL auto_increment PRIMARY KEY First
Adding columns to a table is a common operation, and when MySQL adds columns, you can specify the location of the column
Adding a column to a specified location requires two keywords:
FirstAnd After
FirstIndicates that the column is incremented first
After indicates an increase after a column
Note that MySQL does not use before when adding columns to the specified position, and the first column can be used First, non-first column usesAfter .
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 (one) ' is not null, ' B ' varchar ($) NOT null) Engine=innodb DEFAULT Charset=utf8;
Add a column C after the test table a column:
ALTER TABLE Test ADD COLUMN C INT not NULL after a
Increase 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
Complete the full text.
Add columns to MySQL table at the specified location