dcsimg
Results 1 to 7 of 7

Thread: linking tables in a database

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2017
    Location
    wales
    Posts
    10

    Question linking tables in a database

    hi all, can i connect more than one foreign key from two seperate tables to a primary key in a third table please

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,365

    Re: linking tables in a database

    Do this mean you want one table to be the Primary side of a relationship to more than one table? If that is the question then Yes
    If you mean can one table (child) have a key to two different parent tables then the answer is NO!
    Last edited by GaryMazzone; Nov 22nd, 2019 at 11:46 AM.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,450

    Re: linking tables in a database

    Has this got anything to do with VB.NET? This site has a Database Development forum for questions about database development. I have asked the mods to move this thread.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,450

    Re: linking tables in a database

    Quote Originally Posted by bigmacagain View Post
    hi all, can i connect more than one foreign key from two seperate tables to a primary key in a third table please
    What did you try and what happened when you tried it? If you did something and something unexpected happened, that's important information that we need in order to understand the problem enough to provide a solution. If you haven't tried it then the obvious question is "why not". If you tried it and it worked then there'd be no need to ask the question at all. If you tried it and it didn't work then you could answer my first question.

  5. #5
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,369

    Re: linking tables in a database

    Moved to database section.

    I think I'm interpreting your question differently to Gary because I think the answer's yes. That's probably an indicator that your question's not clear.

    If you are asking, can more than one table have a foreign key to a single table, that's a yes eg, A Customer table might be referenced by an Order Table and a CustomerNote table.

    If you're asking, can one table's foreign key point to two different tables primary key, that's a no. A foreign key has to point to a single primary key (actually, any unique value but if it's not the PK your design smells) on a parent table. Otherwise there would be no way of telling which table it was pointing to.

    If you're asking something else, I'm afraid you'll have to clarify.
    You can depend upon the Americans to do the right thing. But only after they have exhausted every other possibility - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,999

    Re: linking tables in a database

    Quote Originally Posted by FunkyDexter View Post
    If you're asking something else, I'm afraid you'll have to clarify.
    He's from Wales. They are said to have problems with the english language.....

    Agree with FD.
    You have a Table "Client", with Primary Key "ClientNo".
    You have Child-Tables (<-- Plural!) called Accounts and Orders.

    Your Orders-Table might look like this:
    OrderNo.
    ClientNo --> Foreign key to Primary Key in Client-Table

    Your Accounts-Table might look like this
    AccountNo
    IBAN
    ClientNo --> Foreign key to Primary Key in Client-Table
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  7. #7
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,369

    Re: linking tables in a database

    He's from Wales. They are said to have problems with the english language.....
    I'm from just over the water in Bristol. We're not great at it either.
    You can depend upon the Americans to do the right thing. But only after they have exhausted every other possibility - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width