Click here to Skip to main content
14,272,287 members
Rate this:
Please Sign up or sign in to vote.
Can a primary key of one table be a foreign key in another table more than one time. Please see the scenario below:

Table:1
id (pk)
title
referenceID (FK)
oldreferenceID (FK)

Table:2
referenceID (PK)
referenceTitle

Here, can i use "Table:2 referenceID (PK)" as foreign key in "Table:1 referenceID (FK) & oldreferenceID (FK) ?"

Please advise. Thanks in advance.
Posted
Comments
abbaspirmoradi 27-Oct-13 7:05am
   
you should do this with triggers.
adnanrazzaqq 27-Oct-13 7:06am
   
can you please brief how?
Rate this:
Please Sign up or sign in to vote.

Solution 1

Yes, it is absolutely valid, a table can reference the same primary key in several columns.
   
Comments
adnanrazzaqq 27-Oct-13 7:08am
   
Hi! Phil, can you please reference any particular link/tutorial.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Yes. It's pretty normal - think of addresses for example: a company may have a Billing address and a Delivery Address. You would only store each address once, and use Foreign Key references to attach them to the single company. Each address would have a distinct Primary Key.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100