Home All Groups Group Topic Archive Search About

How to link foreign key of one table to Primary key of two table

Author
12 Aug 2006 6:01 PM
prashantdoshi
How to link foreign key of one table to Primary key of two table

Hello Friends,
Here is what I am trying to do.
I have table Expense which has column shop_id,
I've another two tables name L_Shopping and O_Shopping and they have
primary key Shop_id.
Now Expense table's Shop_Id should be the foreign key of L_Shopping and
O_Shopping table. Basically when I enter the record in expense table
the value in shop_id column should present either in L_Shopping or
O_Shopping table's Shop_Id.
Question is How do i add foreign key constraint in Expense table.
Any Help is highly appreciated.
Thank you all.
Regards
Pras..

Author
12 Aug 2006 6:08 PM
David Portas
prashantdo***@gmail.com wrote:
Show quote
> How to link foreign key of one table to Primary key of two table
>
> Hello Friends,
> Here is what I am trying to do.
> I have table Expense which has column shop_id,
> I've another two tables name L_Shopping and O_Shopping and they have
> primary key Shop_id.
> Now Expense table's Shop_Id should be the foreign key of L_Shopping and
> O_Shopping table. Basically when I enter the record in expense table
> the value in shop_id column should present either in L_Shopping or
> O_Shopping table's Shop_Id.
> Question is How do i add foreign key constraint in Expense table.
> Any Help is highly appreciated.
> Thank you all.
> Regards
> Pras..

Combine the common attributes from L_Shopping and O_Shopping into one
table (including shop_id). Now you have a single table for the target
of your foreign key constraint.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Author
12 Aug 2006 6:26 PM
prashantdoshi
David Portas wrote:
Show quote
> prashantdo***@gmail.com wrote:
> > How to link foreign key of one table to Primary key of two table
> >
> > Hello Friends,
> > Here is what I am trying to do.
> > I have table Expense which has column shop_id,
> > I've another two tables name L_Shopping and O_Shopping and they have
> > primary key Shop_id.
> > Now Expense table's Shop_Id should be the foreign key of L_Shopping and
> > O_Shopping table. Basically when I enter the record in expense table
> > the value in shop_id column should present either in L_Shopping or
> > O_Shopping table's Shop_Id.
> > Question is How do i add foreign key constraint in Expense table.
> > Any Help is highly appreciated.
> > Thank you all.
> > Regards
> > Pras..
>
> Combine the common attributes from L_Shopping and O_Shopping into one
> table (including shop_id). Now you have a single table for the target
> of your foreign key constraint.
>
> --
> David Portas, SQL Server MVP
>
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
>
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
Thank you David for your quick reply, Truly Appreciated.

AddThis Social Bookmark Button