Original source: http://www.phpernote.com/MySQL/1120.html
1 frequently used MySQL commands to change the table structure of some SQL statements, including adding, deleting, modifying fields, adjusting the order of the fields. 2 3 To Add a field:4 5ALTER TABLE ' User_movement_log ' Add column Gatewayid int notNULL default0After ' RegionID '; (which field is added later)6 7 To delete a field:8 9 ALTER TABLE ' user_movement_log ' drop column Gatewayid;Ten One To adjust the order of fields: A -ALTER TABLE ' user_movement_log ' Change ' Gatewayid ' "Gatewayid ' int notNULL default0After RegionID; - the //PRIMARY Key - -ALTER TABLE tabelname add new_field_id int (5) unsigneddefault0 notNULLAuto_increment, add PrimaryKey(new_field_id); - + //Add a new column - + ALTER TABLE T2 add d timestamp; AALTER TABLE infos add ex tinyint notNULL default' 0 '; at - //Delete Column - - ALTER TABLE T2 drop column C; - - //Renaming Columns in -ALTER TABLE T1 change a Binteger; to + //changing the type of a column - theALTER TABLE T1 change b b bigint notNULL; *ALTER TABLE infos changeList Listtinyint notNULL default' 0 '; $ Panax Notoginseng //Renaming a table - theALTER TABLE T1RenameT2; + A Gazzo Primer the + MySQL> ALTER TABLE tablename change depno depno int (5) notNULL; - MySQL>ALTER TABLE tablename ADD index index name (field name 1[, field Name 2 ...]); $ MySQL>ALTER TABLE tablename Add index Emp_name (name); $ - index of the plus primary keyword - the MySQL> ALTER TABLE tablename Add primaryKey(ID); - Wuyi index with unique restriction criteria the - MySQL>ALTER TABLE tablename add unique emp_name2 (cardnumber); Wu - Delete an index About $ MySQL>ALTER TABLE tablename DROP INDEX emp_name; - - To Modify a table: - A Add Field: + the MySQL>ALTER TABLE table_name ADD field_name field_type; - $ Modify the original field name and type: the the MySQL>ALTER TABLE table_name change old_field_name new_field_name field_type; the the To delete a field: - in MySQL> ALTER TABLE table_name DROP field_name;
[Linux] [MySQL] command change table structure: Add, delete, modify fields, adjust field order