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 > General > Database Concepts & Design > Supertype Help Please

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-08, 09:14
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Supertype Help Please

I need some help please. Party is the supertype to person, dealer and customer. I am having a difficult time modelling the customer and dealer tables.

This system can have many dealers and a dealer can have many customers. What I need is for every dealer to keep a sequential list of its customer numbers. Sample data might look like this.

Code:
dealer_id     customer_id
1               1
1               2
1               3
2               1
2               2
2               3
Since a subtype cannot contain any other PK other than the PK from the supertype I thought about adding attributes such as customer_id in the customer table and dealer_id in the dealer table and making them alternate keys. I could then link to the dealer_customer table using the AKs.

I tried this but it does not give me my sample data above because the db is enforcing the constraint on the customer_id by not allowing me to duplicate.

Is there another way to do this?

Thanks.

Frank
Attached Images
File Type: bmp export.bmp (654.9 KB, 38 views)

Last edited by Frunkie; 09-21-08 at 09:20.
Reply With Quote
  #2 (permalink)  
Old 09-21-08, 10:12
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
On the odd chance that a customer is fully dependant on dealer (meaning that you can't have a customer without a dealer, that the dealer is in fact an identifying characteristic of the customer), then make the customer PK a composite of dealerId and customerId.

If the customer is an independant entity (meaning that a customer can exist without a dealer, and that a customer can be transferred from one dealer to another), then the only way I know to do what you've described is to create a many-to-many linking table that joins dealers to their customers and put the dealer-relative id in that linking table. This still won't cope with deletions of the link between dealer and customer (which would leave "holes" in your numbering), but it is the closest that I can get.

-PatP
Reply With Quote
  #3 (permalink)  
Old 09-22-08, 02:37
Frunkie Frunkie is offline
Gives Bad Advice
 
Join Date: Mar 2007
Location: 010101010110100
Posts: 791
Thanks for the explanation Pat. I have taken your first approach which still left holes in the customer number. I added another attribute for the customer_no in the customer table which works fine. Whether it is correct or not, I don't know.

Frank
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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