sql创建索引

来源:互联网 发布:淘宝联盟怎么赚钱的 编辑:程序博客网 时间:2024/06/05 01:53
-- 创建索引
-- create index 索引名 on 表名(列名);括号里跟要加索引的列名

-- 删除索引
-- drop index 索引名 on 表名;
drop index userAdress on indextable

-- 在创建表的时候创建索引
create table indexTable(
userId int auto_increment,
userName VARCHAR(50) not null,
PRIMARY KEY (userId),
index (userName)
)

-- 查看索引
show index from indextable

-- 如何修改表
-- 添加索引
alter table 表名 add index(列名);
alter table indexTable add index (userAddress)

-- 删除索引
alter table 表名 drop index 索引名;
alter table indexTable drop index userName

-- 查看表的详细信息
explain SELECT * from indextable where userName='lisi';
-- 创建多列普通索引
-- CREATE INDEX 索引名 ON 表名 (列名1,列名2);这里索引名一样
CREATE INDEX index_pwd_address ON indextable (userPwd,userAddress)