1. Background
Use sql statement to modify table structure
2. Case presentations
Case: table structure the CREATE TABLE `login_user` ( `id` int(32) NOT NULL AUTO_INCREMENT, `name` varchar(225) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '名字', password` ` VARCHAR ( 26 is ) the DEFAULT NULL the COMMENT " password 3 ' , `type` varchar(32) DEFAULT NULL, `state` varchar(32) DEFAULT NULL, `create_time` datetime DEFAULT NULL, `update_time` datetime DEFAULT NULL, `password5` varchar(26) DEFAULT NULL COMMENT '密码5', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; 1 . Modify Field: General data types and modify the properties alter table login_user modify password varchar(25) DEFAULT NULL COMMENT '密码2' 2 . Rename fields: ALTER Table table name change field data type field of the new and old [ attributes ] [ position ] ; alter table login_user change password2 password varchar(26) DEFAULT NULL COMMENT '密码3' 3 . New field: ALTER Table table the Add [ column ] Field Name Data Type [ Column Properties ] [ position ] Location: anywhere in the field may be stored in the table; first: the first position; after: After which field; default after the last field. - added to final ALTER Table login_user the Add password3 VARCHAR ( 26 is ) the DEFAULT NULL the COMMENT " password 4 ' - add a field to the field name specified later alter table + + add + table name field type field to be added to follow the + after + ALTER Table login_user the Add password6 VARCHAR ( 26 is ) the DEFAULT NULL the COMMENT ' password. 6 ' After password 4 Remove fields: the ALTER the Table table name drop field names; alter table login_user drop password5