ホームページ  >  記事  >  バックエンド開発  >  数据库中定义了索引然后应该怎么使用这个索引呢?

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

WBOY
WBOYオリジナル
2016-06-06 20:48:451290ブラウズ

创建表的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的时候,就会用上了

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。