mysql語句:
1、修改表名:
rename table 舊表名 to 新表名;
2、修改字段類型:
alter table 表名 modify column 字段名 字段類型(長度)
3、修改字段名稱和類型:
alter table 表名 change 現有字段名稱 修改后字段名稱 數據類型
4、增加字段:
alter table 表名 add 字段名 字段類型(長度)
//批量增加字段
alter table 表名 add (字段名1 字段類型(長度),字段名2 字段類型(長度),...)
5、刪除字段:
alter table 表名 drop column 字段名
//批量刪除字段
alter table 表名 drop column 字段名1,drop column 字段名2
6、修改字段默認值:
alter table 表名 alter column 字段 set default 默認值
7、添加字段備注:
alter table 表名 add 字段名 字段類型(長度)default null comment '備注'
// 為表添加注釋
alter table 表名 comment '注釋';
索引:
1.普通索引 添加index
alter table 表名
add index 索引名 ( 字段名
)
2.主鍵索引 添加primary key
alter table 表名
add primary key ( 字段名
)
3.唯一索引 添加unique
alter table 表名
add unique ( 字段名
)
4.全文索引 添加fulltext
alter table 表名
add fulltext( 字段名
)
5.如何添加多列索引
alter table 表名
add index 索引名 ( 字段名
, 字段名
, 字段名
)