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 > MySQL > which datatype to use

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-11, 15:36
zr1skydiver zr1skydiver is offline
Registered User
 
Join Date: Aug 2011
Posts: 1
which datatype to use

I have two tables. One is products and the other is product_types. The relationship between the twp has always been 1 to 1. I just found out that a product can now fall under several datatypes. What datatype would I use so that product_type_id in products could contain the values 1,2, and 3?
Reply With Quote
  #2 (permalink)  
Old 08-18-11, 17:04
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
you seriously do not want to do it that way, you're asking for a world of hurt

you need a third table ...
Code:
CREATE TABLE product_producttypes
( product_id INTEGER NOT NULL 
, product_type_id INTEGER NOT NULL 
, PRIMARY KEY ( product_id, product_type_id )
);
INSERT INTO product_producttypes VALUES
 ( 427 , 1 )
,( 427 , 3 )
,( 427 , 4 )
,( 428 , 2 )
,( 429 , 1 )
,( 429 , 3 )
one row per product per product_type

and then remove the product_type_id column from the products table

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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