can two primary keys of two tables act as same foreign key of a table?

Posted by Ganeshd under Sql Server on 8/30/2011 | Points: 10 | Views : 1358 | Status : [Member] | Replies : 3
for example TableA with primary key p1,TableB with primary key p1
in TableC with foreign key p1 .

is it possible to create such constraints in sql if so what is the advantage this?




Responses

Posted by: Rickeybglr on: 8/30/2011 [Member] Starter | Points: 25

Up
0
Down
yes u can create it without any error. but thr is no advantage of ths acc. to me.
for eg table A has primary key P1 with value 1,2,3 and table P2 has values 5,6,7
if u try to insert any of the above values (1,2,3,5,6,7) it ll throw fk_constraint error. bcoz values in table c must satisfy values in both table A and B.
only the intersection of P1, P2 values can insert into table c. if u need ths type of scenario it may be helpful for u.

Ganeshd, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 11/24/2011 [Member] Starter | Points: 25

Up
0
Down
yes u can create Two primary Key for an foreign Key Table..there is no advantage just u can refer two table primary key for single table reference.


Regards
Sriram.r



sriram

Ganeshd, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/25/2012 [Member] Starter | Points: 25

Up
0
Down
PRIMARY KEY TABLES:

CREATE TABLE TABLE1(EMPID INT PRIMARY KEY(EMPID),EMPNAME VARCHAR(90))


CREATE TABLE TABLE2 (EMPID PRIMARY KEY(EMPID),EMPSALARY MONEY)


FOREIGN KEY TABLES:

CREATE TABLE TABLE3(EMPID INT REFERENCES TABLE1(EMPID),EMPJOINDATE DATETIME)

REGARDS



sriram

Ganeshd, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response