Home > Ask the Oracle Database / Applications Experts > Questions & Answers > A list of IDs in a column
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

A list of IDs in a column

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 14 March 2003
I need to create a table which has a field that contains a list of id's to rows in another table. For example, the table portfolioAcc has a field which holds a list of holding accounts for a customer. I would really appreciate any help - thanks in advance.

>

This type of structure, in which one table is related to another through multiple IDs or keys that are stored within a single column, usually in a comma-separated list, can easily get you into trouble. For example,

Customer

 id  name     accounts
 71  J.Smith   12 
 72  B.White   14,24
 73  K.Baker   16,20,26
 75  A.Brown   22

Account id type amount 12 bonds 1047.00 14 stock 937.21 16 bonds 3700.00 20 cash 42.98 22 stock 10456.34 24 cash 211.03 26 stock 2044.65

So B.White has two accounts, a stock account for 937.21, and a cash account for 211.03.

It is easy enough to see how someone can come up with this design. After all, it's called a one-to-many relationship, and sure enough, each customer has one or more accounts. So at first blush, it does indeed look like a one-to-many relationship.

But, alas, the foreign keys are in the wrong table.

The way to relate tables in a one-to-many relationship is to remember that:

  • the "one" table (a.k.a. parent) contains the primary key

  • the "many" table (a.k.a. child) contains the foreign key

So the preferred design is:

Customer

 id  name    
 71  J.Smith 
 72  B.White 
 73  K.Baker 
 75  A.Brown 

Account id custid type amount 12 71 bonds 1047.00 14 72 stock 937.21 16 73 bonds 3700.00 20 73 cash 42.98 22 75 stock 10456.34 24 72 cash 211.03 26 73 stock 2044.65

Space does not permit a full explanation of all the reasons why the comma-separated list of IDs is a poor design. The main problem is that it makes table joins difficult, if not impossible.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts