+ 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
6 Antworten
+ 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,
+ 2
It's a problem case study question an we are required to reference the both on a different table
Hope you understand
+ 2
Okay thanks
+ 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
+ 1
No problem then. Creat 3rd table and in different columns reference to that two id by foreign key
+ 1
Cheers!