研究ノート(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. A複合主キー

# 创建表时,使用表的两列或多列创建复合主键
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
リリース元の4件の記事 ウォンの賞賛0 ビュー26

おすすめ

転載: blog.csdn.net/weiying_zh/article/details/105271184