How to set (combine) two primary keys in a table How to set (combine) two primary keys in a table database database

How to set (combine) two primary keys in a table


The easiest way would be to use a T-SQL command in SSMS Express rather than trying to use the visual designers.....

Once you've designed and created your table, try something like this:

ALTER TABLE dbo.YourTableNameHereADD CONSTRAINT PK_YourTableNameHerePRIMARY KEY(Item_Id, Purchase_Id)


you cannot create two primary keys in a table. You can combine two columns in a table and make as a single primary key

create table table1(col1 int,col2 varchar(20),....Primary key (col1, col2))


you cant have 2 primary keys but you can have a composite primary key, which is a key made of two columns, which is exactly what you got on the [SalesOrderDetail] table with [SalesOrderID] and [SalesOrderDetailID]