今天看到有人的问题,特意查了下。
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为同义词