MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 20th, 2012, 03:13 PM
chrismichaels84 chrismichaels84 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 23 chrismichaels84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 37 m 26 sec
Reputation Power: 0
Serializing Data and Schema Design Question

I am using PHP, though my question isn't a PHP question. When is it appropriate to serialize an array and save it to a database instead of creating relational databases? Here is my specific situation:

I am creating a project management application as a wordpress plugin for my media company. We have several artistic collaborations going on at any given time. I want to be able to create many projects and have users assigned in different roles to one or more of those projects. So, this is what I've come up with:

Code:
-------------------
Table: Users         |
-----------------------------------------------------------------
userid  |   username  |   member_of  |    director_of  |  reader_of  |
-----------------------------------------------------------------
1            michael         3, 7                  1, 3              NULL
-----------------------------------------------------------------
2            kate             1                      2, 7              2
-----------------------------------------------------------------
etc...


-------------------
Table: projects     |
--------------------------------------------------------------
project_id  |   directors                  |   members   |    readers   |
--------------------------------------------------------------
1                 1/michael, 6/James       etc.                etc.
--------------------------------------------------------------
2                 2/kate, 4/Carey            etc.               etc.   
--------------------------------------------------------------
etc...


So I can query either table and parse the strings (or better yet, serialize them as arrays) and have the information I need. Basically, I just need to know by querying the projects who is assigned to that project. I also need to know what projects (and in what capacity) each user is assigned to by querying the user (or multiple users).

However, I'm sure this can be done better through JOINING these tables. I have racked my brain to figure out the best schema and just come up short.

I would really appreciate any thoughts from masters, as I am new at this.

Thank you.

Last edited by chrismichaels84 : December 20th, 2012 at 03:18 PM. Reason: trying to work out spaces in my table

Reply With Quote
  #2  
Old December 20th, 2012, 03:26 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,443 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 14 h 21 m 52 sec
Reputation Power: 4141
storing a comma-delimited list of id numbers in a single column is okay ONLY IF you plan NEVER to search for a specific id within that column

if you cannot meet that very stringent criterion, then you should normalize the data
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old December 20th, 2012, 03:33 PM
chrismichaels84 chrismichaels84 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 23 chrismichaels84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 37 m 26 sec
Reputation Power: 0
Quote:
if you cannot meet that very stringent criterion, then you should normalize the data


Normalize means create a third table as a cross reference and query that table with JOIN statements? If I do that, how do I organize the users table? If the number of projects changes drastically and often?

Reply With Quote
  #4  
Old December 20th, 2012, 04:10 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,443 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 14 h 21 m 52 sec
Reputation Power: 4141
Code:
CREATE TABLE users
( userid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
, username VARCHAR(37) NOT NULL
);
CREATE TABLE projects     
( projectid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT
, descr VARCHAR(37) NOT NULL
);
CREATE TABLE members
( projectid INTEGER NOT NULL 
, userid INTEGER NOT NULL
, PRIMARY KEY ( projectid , userid )
);
CREATE TABLE directors
( projectid INTEGER NOT NULL 
, userid INTEGER NOT NULL
, PRIMARY KEY ( projectid , userid )
);
CREATE TABLE readers
( projectid INTEGER NOT NULL 
, userid INTEGER NOT NULL
, PRIMARY KEY ( projectid , userid )
);

Reply With Quote
  #5  
Old December 20th, 2012, 04:16 PM
chrismichaels84 chrismichaels84 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 23 chrismichaels84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 37 m 26 sec
Reputation Power: 0
You are awesome. Thank you!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Serializing Data and Schema Design Question

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap