+ 1

Making two columns primary keys (composite key) when creating a table in sql server

Two columns need to be primary keys and auto increment how do I go about it Code Create table humanresources.staffid ( StaffID int identity (100,1) not null primary key BranchID as StaffID+100 primary key .......... ......) The code coul not go through. Please I need corrections. Thanks

28th Aug 2020, 11:33 AM
esther iyege
esther iyege - avatar
6 ответов
+ 2
I'm thinking 'BranchID' column could be made a foreign key instead of in a composite. Reference a primary key in (probably) "Branches" table. * Just an idea,
28th Aug 2020, 12:31 PM
Ipang
+ 2
It's a problem case study question an we are required to reference the both on a different table Hope you understand
28th Aug 2020, 12:34 PM
esther iyege
esther iyege - avatar
+ 2
Okay thanks
28th Aug 2020, 12:57 PM
esther iyege
esther iyege - avatar
+ 1
Primary key can be only one. Probably you are seeking branchid to be unique? then just write it. But the better way is make two different tables and set in one of the tables foreign key from other table
28th Aug 2020, 11:51 AM
Shadoff
Shadoff - avatar
+ 1
No problem then. Creat 3rd table and in different columns reference to that two id by foreign key
28th Aug 2020, 12:55 PM
Shadoff
Shadoff - avatar
+ 1
Cheers!
28th Aug 2020, 12:58 PM
Shadoff
Shadoff - avatar