For a small sales related application, we designed database using logical data model. Come to the stage to convert in to physical model. While creating table in SQL Server Management Studio Express, according to our logical data model, we need to combine two attributes to form unique id. Is it possible to combine two primary keys and set it?
But while observing Northwind Sample, we found that in the ORDER DETAILS
table, we can see two primary keys Order Id
& Product Id
. And according to rule table can't have two primary keys. So how it happened in Northwind?
In my case how should I set two columns in my table to make it as two primary keys?
Someone gave suggestion like
To make a two primary key, open the table in design view and click on the two of the required fields and holding CTL, apply primary key
Will this work ??
Edit ;
now my table have 2 PK's in the SSMS . is it valid or it is just a combinationof 2 pks
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.YourTableNameHere
ADD CONSTRAINT PK_YourTableNameHere
PRIMARY 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)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With