日期:2014-05-18  浏览次数:20554 次

主键设置2个字段是什么意思?
主键不是只能设置一列字段吗?为什么可以约束2条字段为主键?

------解决方案--------------------
SQL code

--此处的pid,id就是联合主键
if object_id('pt2') is not null 
drop table pt2
go
create table pt2(
pid int not null,
id int not null
)
go
alter table pt2 add constraint [PK_pt2] primary key(pid,id) on [PRIMARY]
go

------解决方案--------------------
设置两个字段叫联合主键
------解决方案--------------------
可以设置联合主键

 primary key(col1,col2....)