SQL Server 表类型变量中的复合主键

agxfikkp  于 2022-11-21  发布在  其他
关注(0)|答案(1)|浏览(109)

SQL服务器2008:

DECLARE @MyTable TABLE(
    PersonID INT NOT NULL,
    Person2ID INT NOT NULL,
    Description NVARCHAR(100),
CONSTRAINT PK PRIMARY KEY CLUSTERED (PersonID, Person2ID)
);

提供:

Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'CONSTRAINT'.

有没有办法在表值变量中使用复合主键?

bvjveswy

bvjveswy1#

可以按如下方式定义组合主键:

DECLARE @MyTable TABLE
(   
    PersonID INT NOT NULL,    
    Person2ID INT NOT NULL,    
    Description NVARCHAR(100),
    PRIMARY KEY (PersonID, Person2ID)
);

相关问题