当前位置: 代码迷 >> Sql Server >> 主键设立2个字段是什么意思
  详细解决方案

主键设立2个字段是什么意思

热度:29   发布时间:2016-04-27 12:04:30.0
主键设置2个字段是什么意思?
主键不是只能设置一列字段吗?为什么可以约束2条字段为主键?

------解决方案--------------------
SQL code
--此处的pid,id就是联合主键if object_id('pt2') is not null drop table pt2gocreate table pt2(pid int not null,id int not null)goalter table pt2 add constraint [PK_pt2] primary key(pid,id) on [PRIMARY]go
------解决方案--------------------
设置两个字段叫联合主键
------解决方案--------------------
可以设置联合主键

 primary key(col1,col2....)
  相关解决方案