Mysql复合主键和联合主键的区别是什么

数据库   发布日期:2025年04月20日   浏览次数:325

这篇文章主要介绍“Mysql复合主键和联合主键的区别是什么”,在日常操作中,相信很多人在Mysql复合主键和联合主键的区别是什么问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Mysql复合主键和联合主键的区别是什么”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

复合主键:

  1. create table index_test
  2. (
  3. a int not null,
  4. b int not null,
  5. c int not null,
  6. d int null,
  7. primary key (c, a, b)
  8. );

即一个表的主键同时由多个字段共同组成,复合主键索引见【Mysql】复合主键的索引。

联合主键:

  1. create table index_test_a
  2. (
  3. id int not null,
  4. a int not null
  5. primary key (id)
  6. );
  1. create table index_test_b
  2. (
  3. id int not null,
  4. b int not null
  5. primary key (id)
  6. );
  1. create table index_test_a_b
  2. (
  3. id int not null,
  4. a_id int not null,
  5. b_id int not null,
  6. primary key (id)
  7. );
  1. index_test_a_b表的id为表index_test_a和表index_test_b的联合主键,就是个逻辑概念

以上就是Mysql复合主键和联合主键的区别是什么的详细内容,更多关于Mysql复合主键和联合主键的区别是什么的资料请关注九品源码其它相关文章!