How to add composite primary keys in SQL Server 2008?
I have a table as follows.
testRequest (wardNo nchar(5)
, BHTNo nchar(5)
it simple, select columns want to insert primary key and click on Key icon on header and save table
happy coding..,
If you use management studio, simply select the wardNo, BHTNo, testID columns and click on the key mark in the toolbar.
Command for this is,
ALTER TABLE dbo.testRequest
ADD CONSTRAINT PK_TestRequest
PRIMARY KEY (wardNo, BHTNo, TestID)
How about something like
CREATE TABLE testRequest (
wardNo nchar(5),
BHTNo nchar(5),
testID nchar(5),
reqDateTime datetime,
PRIMARY KEY (wardNo, BHTNo, testID)
);
Have a look at this example
How about this:
ALTER TABLE dbo.testRequest
ADD CONSTRAINT PK_TestRequest
PRIMARY KEY (wardNo, BHTNo, TestID)