MySQL multidimensional arrays...

Posted by jay on Stack Overflow See other posts from Stack Overflow or by jay
Published on 2010-03-12T15:30:00Z Indexed on 2010/03/12 15:37 UTC
Read the original article Hit count: 323

What is the best way to store data that is dynamic in nature using MySQL? Let's say I have a table in which one item is "dynamic". For some entries I need to store one value, but for others it could be one hundred values. For example let's say I have the following simple table:

CREATE TABLE manager
( 
name char(50),
worker_1_name(50),
worker_2_name(50),
...
worker_N_name(50)
);

Clearly, this is not an ideal way to set up a database. Because I have to accommodate the largest group that a manager could potentially have, I am wasting a lot of space in the database. What I would prefer is to have a table that I can use as a member of another table (like I would do in C++ through inheritance) that can be used by the "manager" table to handle the variable number of employees. It might look something like this.

CREATE TABLE manager
( 
name char(50),
underlings WORKERS 
);

CREATE TABLE WORKERS 
( 
name char(50),
);

I would like to be able to add a variable number of workers to each manager. Is this possible or am I constrained to enumerating all the possible number of employees even though I will use the full complement only rarely?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about multidimensional-array