mysql索引

来源:互联网 发布:linux下运行jar包 编辑:程序博客网 时间:2024/06/10 02:20
1、创建表时创建索引
[UNIQUE|FULLINDEX] index|KEY [别名](属性名[长度][ASC|DESC])

mysql> create table test1(
    -> id int(10),
    -> name varchar(20),
    -> index(id)     /unique  key uid(id)唯一索引
    -> );
2、在现有表上创建索引
    create [unique|fulltext] index 索引名 on 表名(属性名)
    create unique index uid on ts(id)
    alter table b add unique index uid(id)

查看索引是否被使用:
    不带条件的查询未使用索引
    explain select * from test\G;
    仅按索引字段排序的查询未使用索引
    explain select * from test order by id asc\G;
    *带有索引字段查询条件的查询使用了索引
    explain select * from test where id=1\G;

查看索引
show index from table_name
删除索引
alter table table_name drop index index_name

删除主键约束
alter table test drop primary key;
0 0