ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
来源: https://blog.csdn.net/wyswlp/article/details/8881103 ## 查看表结构 ``` show columns from table_name; show full columns from table_name; ``` ## 修改表名 ``` ALTER TABLE admin_user RENAME TO a_use ``` ## 增加字段及主键 ``` alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id); ``` ## 修改ID为自增,并设置为主键 ``` alter table brand_title_temp_noread modify id int auto_increment primary key ``` ## 列操作 增加字段: ``` ALTER TABLE table_name ADD field_name field_type; ALTER TABLE search_record ADD `send` INT default 0; ``` ## 修改字段类型: ``` alter table search_record alter column big set default 0; alter table search_record modify column big set default 0; ``` ## 在某个字段后增加字段 ``` alter table `user_movement_log` Add column GatewayId int not null default 0 AFTER `Regionid` ``` ## 调整字段顺序 ``` ALTER TABLE `user_movement_log` CHANGE `GatewayId` `GatewayId` int not null default 0 AFTER RegionID ``` ## 修改原字段名称及类型: ``` ALTER TABLE table_name CHANGE old_field_name new_field_name field_type; ALTER TABLE manual_record CHANGE `Note-sort` `Note_sort` varchar(50) DEFAULT NULL; ``` ## 修改字段类型 ``` alter table scholar_keys change hold hold int default 0; ``` ## 删除字段 ``` ALTER TABLE table_name DROP field_name; ``` 修改一个字段 alter table user MODIFY new1 VARCHAR(10);            //修改一个字段的类型 alter table manual_record MODIFY `ORGANIZATION` VARCHAR(500) DEFAULT NULL alter table user CHANGE new1 new4 int;              //修改一个字段的名称,此时一定要重新指定该字段的类型 索引操作: 1.添加PRIMARY KEY(主键索引) mysql>ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2.添加UNIQUE(唯一索引) mysql>ALTER TABLE `table_name` ADD UNIQUE ( `column` ) 3.添加INDEX(普通索引) 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` )