Study Notes (03): mySQL database development tutorial - entity integrity - increment primary keys .camrec

Learning immediately: https://edu.csdn.net/course/play/4364/77139?utm_source=blogtoedu

2. increment primary key (integer):

AUTO_INCREMENT PRIMARY_KEY

Plus 1 increment on the current maximum value of the primary key 

# 创建表时指定自增主键
create table t1
(
sid int primary key not null auto_increasement
sname char(10)
)

# 添加自增主键
alter table s2 modify column sid int auto_increment primary key

# 删除自增(删除后仍是主键但没有自增功能)
alter table s2 modify column sid int not null

 

3. A composite primary key

# 创建表时,使用表的两列或多列创建复合主键
create table f
(
sid int,
kid int,
mark int,
primary key (sid, kid)
)

# 添加复合主键
alter table f2 add primary key (sid, kid)

# 删除复合主键
alter table f2 drop primary key
Released four original articles · won praise 0 · Views 26

Guess you like

Origin blog.csdn.net/weiying_zh/article/details/105271184