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

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

WBOY
Release: 2016-06-06 20:48:45
Original
1335 people have browsed it

创建表的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>
Copy after login
Copy after login

上面创建了一个index索引

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

想请问这个索引创建了以后如何使用呢,查询的时候会有什么不同的语法出现吗 这个索引的名字是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>
Copy after login
Copy after login

上面创建了一个index索引

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template