Help with the SQL Script.

I have a table A with two columns as Primary Key. Is it firstly possible.

Secondly, if the first column of table A(say C1) is set as PK1 and Foreign Key to another primary key column of table B.

Similarly, second column of table A (say C2) is set as PK2 and Foreign Key to another column of table C.

I wish to have a table created and the data to be added to C1 of Table A  should allow repeatation( ie duplicate entries should be permissible.

In my limited understanding, can the C1 be a combination of PK1 and FK?

I am using SQL Server 2008

Please advise
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
You cannot have two primary keys. But you can have primary key with compound columns (that is say in simplistic terms, more than one column).

You can then have two separate unique keys on these two columns. And then you can have two corresponding FKs. FK doesn't necessarily asks for a PK (it's just been convention), it can work with UK as well.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nitin SontakkeDeveloperCommented:
I wish to have a table created and the data to be added to C1 of Table A  should allow repeatation( ie duplicate entries should be permissible.

The above is possible ONLY IF you have a compound keys. However, then again, only one combination C1 + C2 would be allowed. So you can A + A, A + B, A + C, A + D and so on but no other A + A is allowed, of course!
Scott PletcherSenior DBACommented:
Yes.  Two (or more) columns can make up the PK.  And each column of the PK could be a FK to another table.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Member_2_7967119Author Commented:
Nitin Sontakke,

Can you provide me the table script to build the composite key.

Member_2_7967119Author Commented:
Do not worry, I got it. Thank you for your inputs.
Member_2_7967119Author Commented:
Thank you for your valuable inputs.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.