加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql中unique key中在查询中的使用

发布时间:2020-12-12 00:02:20 所属栏目:MySql教程 来源:网络整理
导读:1、建表语句: 2、添加unique key: 3、查询测试语句: -- 包含索引所有字段,但顺序和索引不一致 select * from employees where gender='M' and first_name='Chirstian'; -- key列值:idxunique_first_name_gender -- 包含索引第一个字段 select * from emp

1、建表语句:

2、添加unique key:

3、查询测试语句:

-- 包含索引所有字段,但顺序和索引不一致
select * from employees where gender='M' and first_name='Chirstian';
-- key列值:idxunique_first_name_gender

-- 包含索引第一个字段
select * from employees where first_name='Chirstian';
-- key列值:idxunique_first_name_gender

-- 包含索引的非第一个字段
select * from employees where gender='M';
-- key列值:NULL

4、总结:在查询时,如果where条件里面只有unique key里面的列(部分或者全部)且列值类型为const。如果要使用unique key,where里面必须得有建立unique key时的第一列,其他列随意。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读