Home  >  Article  >  Backend Development  >  数据库中定义了索引然后应该怎么使用这个索引呢?

数据库中定义了索引然后应该怎么使用这个索引呢?

WBOY
WBOYOriginal
2016-06-06 20:48:451288browse

创建表的sql语句如下

<code class="lang-sql">create table if not exists users(
user_id mediumint unsigned not null auto_increment,
username varchar(30) not null,
pass char(40) not null,
first_name varchar(20) not null,
last_name varchar(40) not null,
email varchar(60) not null,
primary key (user_id),
unique (username),
unique (email),
index login (pass, email)
)engine = innodb
</code>

上面创建了一个index索引

<code class="lang-sql">index login (pass, email)
</code>

想请问这个索引创建了以后如何使用呢,查询的时候会有什么不同的语法出现吗 这个索引的名字是login,到时候直接用login查询而不需要pass和email了? 求各位大大解答一下啊

回复内容:

创建表的sql语句如下

<code class="lang-sql">create table if not exists users(
user_id mediumint unsigned not null auto_increment,
username varchar(30) not null,
pass char(40) not null,
first_name varchar(20) not null,
last_name varchar(40) not null,
email varchar(60) not null,
primary key (user_id),
unique (username),
unique (email),
index login (pass, email)
)engine = innodb
</code>

上面创建了一个index索引

<code class="lang-sql">index login (pass, email)
</code>

想请问这个索引创建了以后如何使用呢,查询的时候会有什么不同的语法出现吗 这个索引的名字是login,到时候直接用login查询而不需要pass和email了? 求各位大大解答一下啊

例如,你的SQL是SELECT * FROM users WHERE pass = 'xxxxx' AND email = 'xxxxx' LIMIT 1的时候,就会用上了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn