If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Help with master detail table design

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-10, 06:20
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Help with master detail table design

Hey fellows, hope you are all are good

I have two tables in database with 1 to many relation (master/child). The tables already have a lot of record entries in them.

Now it is identified that the master can repeat in some entries also ( so the master becomes another child table)

In my discussion with manager we discussed two solutions
  • I proposed to make a new table and reference the previous master table's primary key in it
  • Manager insists on not creating a new table but to include a reference_id column in the existing master table and repeat the reference the new records in the same master table.

I am totally confused on what to do here? I feel that referencing the existing master in a new table would be more beneficial and save us from redundancy ?

What do you guys say ? Any convincing advise which I can get from you fellows and give to my manager ?

Best regards, Mike.
Reply With Quote
  #2 (permalink)  
Old 03-09-10, 09:07
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,473
I do not understand what you need to do. Can you elaborate? Please provide examples to illustrate your entire situation.

Andy
Reply With Quote
  #3 (permalink)  
Old 03-09-10, 10:49
Cougar8000 Cougar8000 is offline
Registered User
 
Join Date: Nov 2005
Location: IL
Posts: 552
Dude, if you already have a PK in your Master table, then you can not have duplicate records in it.

DDL for both tables would help.
__________________
--
IBM Certified DBA on DB2 for Linux, UNIX, and Windows

DB2 v9.1.0.2 os 5.3.0.0
Reply With Quote
  #4 (permalink)  
Old 03-09-10, 10:58
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Hi consider the following example, my advice was turned down eventually maybe you guys can advice me better. Check the images.
Mike.
Attached Thumbnails
Help with master detail table design-1.png   Help with master detail table design-2.png   Help with master detail table design-3.png  
Reply With Quote
  #5 (permalink)  
Old 03-09-10, 11:31
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,473
So basically what your company want to do is take your current "Department" table and have a sub-department entity and the profit-detail needs to be under the sub-department, not the department like it is now.

My question, is how do you know which profit-detail records go to which new sub_department?

Andy
Reply With Quote
  #6 (permalink)  
Old 03-09-10, 12:52
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Along with redundancy in similar rows of the same department with the 3rd approach, thats a good point you made.

I was told to leave it up to the user to enter the reference_ID and in case he makes a typo the records wont go with the correct department. ( Sometimes convincing people is hard so I made a thread to get some good valid points)
Reply With Quote
  #7 (permalink)  
Old 03-09-10, 12:59
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,473
That was not my point. You will have sub_departments with whichever method you choose. The point I am trying to make is your current data. Right now you have profit_detail data that is pointing to, for example, the SALES department. What sub-department are you going to change the current profit-detail records?

Andy
Reply With Quote
  #8 (permalink)  
Old 03-10-10, 00:51
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Hi, Like currently

for Sales department there are
Hardware
Computers
Routers

It is identified now that any department can have many new sub departments for new records

So if there were a new sales department "Sales 2" we may have it as

Sales "2" under a new category Sales

So previous sales would become Sale1 logically so at report time the structure must be

Sales
Sale 1
Computers
Hardware
Routers
Sale 2
(All the new details)

Existing records wont change they will keep under the same but logically the table should accommodate new records under a new head.

Mike.


Quote:
Originally Posted by ARWinner View Post
That was not my point. You will have sub_departments with whichever method you choose. The point I am trying to make is your current data. Right now you have profit_detail data that is pointing to, for example, the SALES department. What sub-department are you going to change the current profit-detail records?

Andy
Reply With Quote
  #9 (permalink)  
Old 03-10-10, 09:45
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,473
So what you are saying is that the profit-detail data will not change at all. You plan to just change the current department rows to reflect the sub-departments and add new rows for the remaining sub-departments.

I tend to want to keep things as simple as possible, so I would have to go with you boss's idea by just adding a column that is the super-department. Your idea, although sound (and the way it probably should have been from the beginning) is not practical now because of the amount of maintenance it would require.

Andy
Reply With Quote
  #10 (permalink)  
Old 03-11-10, 07:48
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Yes but the existing table has only about 10 records now. I only wonder this idea would be fruitful on long term basis.
Reply With Quote
  #11 (permalink)  
Old 03-11-10, 09:13
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,473
How many rows will it contain when all of the sub-departments have been added? How many records are in the profit-detail table?

Andy
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On