mysql>ALTER TABLE test RENAME TO test_old
2).增加主键
mysql>alter table tabelname add new_field_id int(10) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
修改ID为自增,并设置为主键
mysql>alter table brand_title_temp_noread modify id int auto_increment primary key;
3).列操作:
增加字段:
mysql> ALTER TABLE table_name ADD field_name field_type;
mysql>ALTER TABLE search_record ADD `send` INT default 0;
4).修改字段类型:
mysql>alter table search_record alter column big set default 0;
5).在某个字段后增加字段:
mysql>alter table `user_movement_log` Add column GatewayId int not null default 0 AFTER `Regionid`
6).调整字段顺序:
mysql>alter table `user_movement_log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID
7).修改原字段名称及类型:
mysql> alter table table_name CHANGE old_field_name new_field_name field_type;
mysql>ALTER TABLE manual_record CHANGE `Note-sort` `Note_sort` varchar(50) DEFAULT NULL;
修改字段类型:
mysql>alter table scholar_keys change hold hold int default 0;
删除字段:
mysql> ALTER TABLE table_name DROP field_name;
修改一个字段
mysql>alter table user MODIFY new1 VARCHAR(10); //修改一个字段的类型
mysql>alter table manual_record MODIFY `ORGANIZATION` VARCHAR(500) DEFAULT NULL
mysql>alter table user CHANGE new1 new4 int; //修改一个字段的名称,此时一定要重新指定该字段的类型
8).索引操作:
1.添加PRIMARY KEY(主键索引)
mysql>ALTER TABLE `table_name` ADD PRIMARY KEY (`column`);
2.添加UNIQUE(唯一索引)
mysql>ALTER TABLE `table_name` ADD UNIQUE (`column`);
3.添加INDEX(普通索引)
mysql>ALTER TABLE `table_name` ADD INDEX index_name (`column`);
4.添加FULLTEXT(全文索引)
mysql>ALTER TABLE `table_name` ADD FULLTEXT (`column`);
5.添加多列索引
mysql>ALTER TABLE `table_name` ADD INDEX index_name(`column1`, `column2`, `column3`);