ALTER TABLETestADD COLUMNIdINTUNSIGNED not NULLAuto_incrementPRIMARY KEYfirst, adding a column to a table is a common operation, and when MySQL increments the column, you can specify that the column's location should be two keywords for the specified location. Note that MySQL does not use the before when adding columns to the specified position, the first column can use the after with first, not column one. Syntax:ALTER TABLEtable_nameADD [COLUMN] col_nameColumn_definition[First | After Col_name]Example:DROP TABLE IF EXISTS' test ';CREATE TABLE' Test ' (' a 'int( One) not NULL, ' B 'varchar( $) not NULL) ENGINE=InnoDBDEFAULTCHARSET=UTF8; Add a column C after the test table a column:ALTER TABLETestADD COLUMNCINT not NULLafter a adds the field ID in the first column of the test table:ALTER TABLETestADD COLUMNIdINTUNSIGNED not NULLAuto_incrementPRIMARY KEYFirst, move the ID column to column one:ALTER TABLE' table_name ' change ' ID ' ID 'int not NULLAuto_increment first;
MySQL add column, move column