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