MySQL_Table_Index_Action

本文介绍了如何在SQL中创建不同类型的索引,包括普通索引、唯一索引、别名索引及多列索引,并详细展示了如何通过SQL语句进行索引的创建、添加与删除操作。

    1. Create

    i. index

Create table t_user1(
	id int,
	userName varchar(20),
	password varchar(20),
	index (userName)
);

122300_ZFwN_2363350.png

122408_iJYx_2363350.png

    ii. Unique index

Create table t_user2(
	id int,
	userName varchar(20),
	password varchar(20),
	unique index (userName)
);

122605_Xmew_2363350.png

    iii. Alias

Create table t_user3(
	id int,
	userName varchar(20),
	password varchar(20),
	unique index index_userName (userName)
);

122802_ODra_2363350.png

    iv. Multi column index

Create table t_user4(
	id int,
	userName varchar(20),
	password varchar(20),
	index index_userName_password (userName, password)
);

122929_tyxe_2363350.png


    2. Add --> Create ... on

Create index index_userName on t_user5(userName);

123152_SS3V_2363350.png


    3. Alter ... add ...

Alter table t_user6 add index t_userName (userName);

123517_la3K_2363350.png

    

    4. Drop

Drop index t_userName on t_user6;

123613_tEVc_2363350.png


转载于:https://my.oschina.net/u/2363350/blog/671474

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值