立即学习:https://edu.csdn.net/course/play/4364/77139?utm_source=blogtoedu
2. 自增主键(整数型):
AUTO_INCREMENT PRIMARY_KEY
在当前主键最大值上加1自增
# 创建表时指定自增主键
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. 复合主键
# 创建表时,使用表的两列或多列创建复合主键
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