INDEX && PRIMARY KEY && UNIQUE KEY
When I have do some sql tody, some confusion come up to me.
Its about the index && PRIMARY KEY && UNIQUE KEY in MySQL. So I google it for the answers. There is a clearly answer on the
StackOverflow. So I share it on this BLOG.
About INDEX:
Firstly, we should understand KEY and INDEX are synonyms in MySQL. They mean the same thing.
You may have the quersion : what is exactly the INDEX mean ?
Here is a shortcut about the INDEX:
In databases you would use indexes to improve the speed of data retrieve. An index is typically created on columns used in
JOIN, WHERE, and ORDER BY clauses.
There is an example about INDEX so you can understand it better :
Imagine you have a table called users
and you want to search for all the users which have the last name 'Smith'. Without an index, the database would have to go through all the records of the table: this is slow, because the more records you have in your database, the more work it has to do to find the result. On the other hand, an index will help the database skip quickly to the relevant pages where the 'Smith' records are held. This is very similar to how we, humans, go through a phone book directory to find someone by the last name: We don't start searching through the directory from cover to cover, as long we inserted the information in some order that we can use to skip quickly to the 'S' pages.
About PRIMARY KEY :
Primary keys and unique keys are similar. A primary key is a column, or a combination of columns, that can uniquely identify a row.
the five rules of primary key :
1. The data in a primary key can't be repeated. (Because primary key is a special kind of unique key)
2. A primary key must have a value.
3. The primary key must be set when a new row is inserted.
4. A primary key must be as efficient as possible.
5. The value of a primary key can't be changed
About UNIQUE KEY:
When you specify a unique key on a column, no two distinct rows in a table can have the same value.
The columns in which no two rows are similar .
Also note that columns defined as primary keys or unique keys are automatically indexed in MySQL.
Primary key does not allow null value but unique key allows null value.
INDEX && PRIMARY KEY && UNIQUE KEY的更多相关文章
- MySQL 中 key, primary key ,unique key,index的区别
一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id int(11) NOT NULL auto_increment, user_n ...
- 【Mysql】key 、primary key 、unique key 与index区别
参考:https://blog.csdn.net/nanamasuda/article/details/52543177 总的来说,primary key .unique key 这些key建立的同时 ...
- MySQL - primary key PK unique key,key PK index
primary key PK unique key 总结 primary key = unique + not null 主键不能为空每个字段值都不重复,unique可以为空,非空字段不重复 uniq ...
- mysql中key 、primary key 、unique key 与index区别
一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id ) NOT NULL auto_increment, ) default NU ...
- MySQL中KEY、PRIMARY KEY、UNIQUE KEY、INDEX 的区别
参考:MySQL中KEY.PRIMARY KEY.UNIQUE KEY.INDEX 的区别 对于题目中提出的问题,可以拆分来一步步解决.在 MySQL 中 KEY 和 INDEX 是同义.那这个问题就 ...
- 待续--mysql中key 、primary key 、unique key 与index区别
mysql中key .primary key .unique key 与index区别
- mysql中 key 、primary key 、unique key 和 index 有什么不同
mysql中 key .primary key .unique key 和 index 有什么不同 key 是数据库的物理结构,它包含两层意义和作用, 一是约束(偏重于约束和规范数据库的结构完整性), ...
- Mysql中的索引()key 、primary key 、unique key 与index区别)
CREATE TABLE pre_forum_post ( pid int(10) unsigned NOT NULL COMMENT '帖子id', fid mediumint(8) unsigne ...
- PRIMARY KEY,key,unique key
主键索引(必须指定为“PRIMARY KEY”,没有PRIMARY Index). 唯一索引(unique index,一般写成unique key). 普通索引(index,只有这一种才是纯粹的in ...
随机推荐
- 死磕 java原子类之终结篇(面试题)
概览 原子操作是指不会被线程调度机制打断的操作,这种操作一旦开始,就一直运行到结束,中间不会有任何线程上下文切换. 原子操作可以是一个步骤,也可以是多个操作步骤,但是其顺序不可以被打乱,也不可以被切割 ...
- Hi,bro
这是我第一次写部落格,也是我刚开始学python,希望我以后能把To Do List 做好,也希望大家可以好好学习,为了以后good life去努力,Do SomeThing OK?
- vue2.0:(八-2)、外卖App弹窗部分sticky footer
什么是sticky-footer ? 如果页面内容不够长的时候,页脚块粘贴在视窗底部,如果内容足够长时,页脚块会被内容向下推送.那具体要怎么做呢?下面以外卖App为例: 第一种方法:这个自己用过,是好 ...
- centos上手动安装最新版本ELK
软件包下载地址:https://www.elastic.co/downloads/elasticsearch 1,安装es #tar zxvf elasticsearch-2.3.4.tar.gz # ...
- Windows 7, Visual Studio 2015下编译Webkit
因工作需要,需要编译Windows版本的Webkit,中间走了不少弯路,都记录下来,供大家参考!也随时欢迎大家讨论(QQ群:345802342) 整个编译工作参考的是官方文档:https://webk ...
- 微软分布式机器学习工具包DMTK——初窥门径
在现在机器学习如日中天的大背景下,微软亚洲研究院的实习岗位中,机器学习组的工作也是维护DMTK,参与算法改进,那么在此之前我们得了解DMTK是个啥. DMTK由一个服务于分布式机器学习的框架和一组分布 ...
- Predicate Programming Guide
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/AdditionalChap ...
- Python面向对象(三)
类的使用:实例化.属性引用 实例化 g1 = Garen('草丛伦1') # 实例化 g2 = Garen('草丛伦2') g3 = Garen('草丛伦3') 类的属性:变量和函数 print(Ga ...
- Cenos7—安装
1. 进入安装界面 2. 选择语言 3. 进行分区 4. 设置root密码
- VMware vSphere6.0 服务器虚拟化部署安装图解
一 VMware vSphere部署的前期规划要点 1 vSphere的优点 (略) 2 如何利用现在的设备架构虚拟化环境 在虚拟化过程中,用户大多会考虑目前现有的服务器.存储.交换机等基础设备是否可 ...