Mysql中key关键词和autoincrement解释

今天看到有人的问题,特意查了下。

1.autoincrement作用,之前一直以为是主键每插一条记录自动增长对应值的意思,然后发现并不是,其实表示的是从对应值开始增长

以下摘自https://www.w3school.com.cn/sql/sql_autoincrement.asp

MySQL 使用 AUTO_INCREMENT 关键字来执行 auto-increment 任务。

默认地,AUTO_INCREMENT 的开始值是 1,每条新记录递增 1。

要让 AUTO_INCREMENT 序列以其他的值起始,请使用下列 SQL 语法:

ALTER TABLE Persons AUTO_INCREMENT=100

2.key关键词的作用

以下摘自:https://www.quora.com/What-is-the-difference-between-using-KEY-and-INDEX-in-MySQL

Strictly speaking, a KEY is a constraint (something that is a KEY candidate is a column that is not nullable and has a uniqueness constraint) and an INDEX is a data structure that is needed in order to implement a KEY constraint in an efficient way (in order to actually enforce a uniqueness constraint you need to check if a value is present before inserting it - in order to do that fast you need an index to do the lookup).

The binding between the two is so tight that database people often use both words interchangeably and in fact the keywords KEY and INDEX can be used interchangeably in SQL commands.

上述大概可理解为,key是概念上的东西,index为具体实现,但是实际上可以认为key和index为同义词

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值