什么是复合主键

  主键是唯一的索引,通常会用GUID最为主键,但是并不是每个表都存在ID字段,例如学生表(姓名,生日,性别,班级),这里面每一个值都可能重复,无法使用单一字段作为主键,这时我们可以将多个字段设置为复合主键,由复合主键标识唯一性。只要不是复合主键每个值都重复,就不算重复。

create table student 
( 
   name varchar(16), 
   birth date, 
   sex bool, 
   class int,
   primary key (name,birth,sex,class) 
)

猜你喜欢

转载自www.cnblogs.com/stilldream/p/10435628.html