|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to link foreign key of one table to Primary key of two tableHow 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.. prashantdo***@gmail.com wrote:
Show quote > How to link foreign key of one table to Primary key of two table Combine the common attributes from L_Shopping and O_Shopping into one> > 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.. 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 -- David Portas wrote:
Show quote > prashantdo***@gmail.com wrote: Thank you David for your quick reply, Truly Appreciated.> > 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 > -- |
|||||||||||||||||||||||