mysql——主键自动增长&唯一索引

首先说一下主键和唯一索引的区别

主键:一个数据库的一张表有且仅有一个主键,而且主键不能重复

唯一索引:一个数据库的一张表上唯一索引可以有多个,只是所在唯一索引上的值不能重复,这一点和主键一样


下面我们创建一个有主键有唯一索引的,并且主键是自动增长

create table demo
 (id int primary key auto_increment, 
name char(10) unique key, 
age int);

接下来我们插入数据看看


猜你喜欢

转载自www.cnblogs.com/xiaostudy/p/9373982.html