In the traditional relational database structure, each row and column should store only one value.
Do not keep lists separated by commas or something ridiculous.
For example, they say that there are seven people in a sports team. You can do it:
CREATE TABLE team ( team_id INT PRIMARY KEY, team_name VARCHAR(50), team_members VARCHAR(200) ); INSERT INTO team VALUES (1,'Dwarfs', 'Sleepy,Dopey,Sneezy,Happy,Grumpy,Doc,Bashful')
But better to do this:
CREATE TABLE team ( team_id INT PRIMARY KEY, team_name VARCHAR(50), ); INSERT INTO team (team_name) VALUES ('Dwarfs'); CREATE TABLE team_members ( team_id INT, member_name VARCHAR(20), FOREIGN KEY (team_id) REFERENCES team(team_id) ); INSERT INTO team_members VALUES (LAST_INSERT_ID(), 'Sleepy'), (LAST_INSERT_ID(), 'Dopey'), (LAST_INSERT_ID(), 'Sneezy'), (LAST_INSERT_ID(), 'Happy'), (LAST_INSERT_ID(), 'Grumpy'), (LAST_INSERT_ID(), 'Doc'), (LAST_INSERT_ID(), 'Bashful');
nb: LAST_INSERT_ID() is a MySQL function. Similar solutions are available in other brands of the database.
Bill karwin
source share