mysql脚本模式创建索引_mysql创建脚本索引范例

查看表中索引的方法:

show index from table_name; 查看索引

索引的类型及创建例子::

1.PRIMARY KEY (主键索引)

alter table table_name add primary key ( `column` );

2.UNIQUE 或 UNIQUE KEY (唯一索引)

alter table table_name add unique (`column`);

3. 删除索引

alter table 表名 drop index 索引名;

4.INDEX (普通索引)

alter table table_name add index index_name ( `column` );

5.多列索引 (聚簇索引)

alter table `table_name` add index index_name ( `column1`, `column2`, `column3` );

6.修改表中的索引:

alter table `table_name` drop primary key,add primary key(`column1`, `column2`);

修改列名 增加列明

1.添加字段:

alter table `tablename` Add column `column` int not null default 0;

2.删除字段:

alter table `tablename` drop column `column`;

3.调整字段顺序:

ALTER TABLE `tablename` CHANGE `column1` `column1` int not null default 0 AFTER `column2`;

4.重命名列

alter table `tablename` change `column1` `column2` integer;

5.改变列的类型

alter table `tablename` change  `column1`  `column1` bigint not null;

6.修改字段

alter table 表名 change 旧字段名 新字段名 字段类型;

alter table 表名 modify 字段名 字段类型;//修改字段类型

alter table student change name name varchar(20)not null default 'liming';//修改字段类型 default后边是

字段默认的值

alter table student change name name1 varchar(20)not null default 'liming';//修改字段名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值