mysql数据库sql常用命令

时间:2024-01-07 22:11:20

1、查看索引:mysql> show index from tblname;

2、利用索引查询:SELECT * FROM product WHERE ID > =(select id from product limit 866613, 1) limit 20

或者

SELECT * FROM product a JOIN (select id from product limit 866613, 20) b ON a.ID = b.id

3、创建单个索引和联合索引

首先创建一个表:create table t1 (id int primary key,username varchar(20),password varchar(20));

创建单个索引的语法:create index 索引名 on 表名(字段名)

索引名一般是:表名_字段名

给id创建索引:create index t1_id on t1(id);

创建联合索引的语法:create index 索引名 on 表名(字段名1,字段名2)

给username和password创建联合索引:create index t1_username_password on t1(username,password)