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 > How to design DB to support adding extra attributes?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-26-03, 10:42
nvtluong nvtluong is offline
Registered User
 
Join Date: Mar 2003
Posts: 5
How to design DB to support adding extra attributes?

Hi,

I'm learning to develop an online webstore. The stores sell numerous different types of item. Each type of item requires different set of attributes (i.e different list of specifications). Certainly they have a common set of attributes such as Name, Price and Available quantity.

Specifically, if I sell 3 types of items: Electronics, Clothes and Foods, I need to add attributes that are specific to Electronics such as Power, Voltage... These attributes are not applicable for Clothes or Foods. And for Clothes I surely need other specific info such as Size, Material...

Hence the problem is how to freely add new attributes for an item and the solution should be applicable for a Relational DB.

A tentative solution I have is to create two tables: Items, ItemInfo tables. Items will store common attributes and extra info goes to ItemInfo table. The structure of ItemInfo is: (id_item,attr_name,attr_value). Then to gather info for an item, I need to do a join. The bad thing about this design is the join return multiples with each row for 1 extra attribute. This is not nice for my Java code to parse the result and populate object. It also wastes bandwidth as common attributes will be repeated on every row of the result set.

Sorry for writing so long. I just want to explain it carefully.
Any idea is welcomed!

Thanks,

Luong Nguyen.
Reply With Quote
  #2 (permalink)  
Old 09-29-03, 18:14
saracen saracen is offline
Registered User
 
Join Date: Sep 2003
Location: London
Posts: 5
Try an 'extension' table for each Item. The application should be designed to insert into the correct extension table for that item type.

ITEM
item_id, item_desc, item_type

ITEM_CD
item_id, cd_artist, cd_title

ITEM_BOOK
item_id, book_author, book_title

etc....

If on the other hand their are so many different item types, and these will change over time it may be better to have an ATTRIBUTES table, where any item can have multiple rows in that ATTRIBUTES table. This will make your queries and forms more difficult to design.
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