复合主键的问题
Create table #temp(
No int primary key ,
Name char(10)
)
现在想让No和Name 都为主键怎么写?
------解决方案--------------------CONSTRAINT PK_emp_id PRIMARY KEY(no,name)
------解决方案--------------------CREATE TABLE #temp(
No int ,
Name char(10) ,
CONSTRAINT [PK_Temp] PRIMARY KEY CLUSTERED (No,name)
)
------解决方案--------------------Create table temp(
No int ,
Name char(10)
constraint pk_idname PRIMARY KEY([no],[name]))
------解决方案--------------------楼主在联机帮助里,很详细和例子:
打开联机帮助—输入—create table
------解决方案--------------------CREATE TABLE [表名] (
[F1] [int] NOT NULL ,
[F2] [int] NOT NULL ,
[num] [int] NULL ,
CONSTRAINT [PK_表名] PRIMARY KEY CLUSTERED
(
[F1],
[F2]
) ON [PRIMARY]
) ON [PRIMARY]
GO
------解决方案--------------------Create table temp(
No int ,
Name char(10)
constraint pk_idname PRIMARY KEY([no],[name]))