연구 노트 (03) : MySQL의 데이터베이스 개발 튜토리얼 - 엔티티 무결성 - 증가 기본 키 .camrec

바로 학습 : 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
출시 사 원저 · 원의 칭찬 0 · 조회수 26

추천

출처blog.csdn.net/weiying_zh/article/details/105271184