Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Multiple values associated with a single value

Multiple values associated with a single value

Scheduled Pinned Locked Moved Database
tutorialquestiondatabasedesign
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shrims4u
    wrote on last edited by
    #1

    Hi all, I want a trick as to how to add multiple values for a single value . For example : A Person named "A" has two cars "Car1" , "Car2" How do I design the database for this ??

    R C 2 Replies Last reply
    0
    • S shrims4u

      Hi all, I want a trick as to how to add multiple values for a single value . For example : A Person named "A" has two cars "Car1" , "Car2" How do I design the database for this ??

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      You have a table Person keyed say on PersonId. You also have a table Car, keyed on CarId. Also in this table you have a PersonId fogeign key to the first table. Each Person can then own multiple cars, and to see which you need to do a query with a 'join'.

      Regards, Rob Philpott.

      1 Reply Last reply
      0
      • S shrims4u

        Hi all, I want a trick as to how to add multiple values for a single value . For example : A Person named "A" has two cars "Car1" , "Car2" How do I design the database for this ??

        C Offline
        C Offline
        Corporal Agarn
        wrote on last edited by
        #3

        Hello, Rob Philpott has the right idea. Do not forget to index the combination table. If you want to have only one table then I would suggest having an ID, Person, and Car columns that way the ID could be your primary key and you could have an index on the person column and one on the car column. However, Rob's way is the proper way to setup a database.

        A 1 Reply Last reply
        0
        • C Corporal Agarn

          Hello, Rob Philpott has the right idea. Do not forget to index the combination table. If you want to have only one table then I would suggest having an ID, Person, and Car columns that way the ID could be your primary key and you could have an index on the person column and one on the car column. However, Rob's way is the proper way to setup a database.

          A Offline
          A Offline
          AmbiguousName
          wrote on last edited by
          #4

          I think Rob's idea is better as it is easy to handle, rather than to make All-in-One table. There is really a basic databse rule invloved here that we should make another table for the multi-valued attributes. Parent table's primary key will be foriegn in the newly made table.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups