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 > Data Access, Manipulation & Batch Languages > ANSI SQL > storing values in different tables based on data type

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-18-06, 06:37
rudgr rudgr is offline
Registered User
 
Join Date: Mar 2006
Posts: 8
storing values in different tables based on data type

LS,

Suppose I need to store multiple properties of multiple data types. Wat would be the best way to store the property values?

Like:

PROPERTIES(ID,NAME,VALUE_TYPE)

PROPERTY_VALUES_NUMERIC(ID,NUMERIC_VALUE,PROPERTY_ ID)
PROPERTY_VALUES_STRING(ID,STRING_VALUE,PROPERTY_ID )
PROPERTY_VALUES_DATE(ID,DATE_VALUE,PROPERTY_ID)
...

Or:

PROPERTY_VALUES(ID,NUMERIC_VALUE,TRING_VALUE,DATE_ VALUE,...,PROPERTY_ID)

Suppose I choose the first option and I needed to construct a SQL query to display all properties and their respective value, what would the SQL look like? Is it possible to (LEFT) JOIN the PROPERTIES records to their value in the respective PROPERTY_VALUES_... table based on the VALUE_TYPE stored in the PROPERTIES table? Something like:

IF VALUE_TYPE == NUMERIC > LEFT JOIN PROPERTY_VALUES_NUMERIC ON ...
IF VALUE_TYPE == STRING> LEFT JOIN PROPERTY_VALUES_STRING ON ...
IF VALUE_TYPE == DATE> LEFT JOIN PROPERTY_VALUES_DATE ON ...

Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 03-18-06, 08:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
neither method looks at all attractive

i think you are trying to abstract a design?

why not model the real data?

see OTLT and EAV: the two big design mistakes all beginners make
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-18-06, 08:46
rudgr rudgr is offline
Registered User
 
Join Date: Mar 2006
Posts: 8
Hi,

thanks for the quick reply.

The problem is that I don't know the number and type of properties in advance. I need a data desig that enables me to let the user specify specific properties.

Consider for instance a car parts product catalog, where all products share common properties such as name, description. The products also have product specific properties. For a exhausts I need to store the the diameter, but for the multi cd player I need to store the number of cd's.
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