Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 1883 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

MySQL Database organization question

Thread title: MySQL Database organization question
Closed Thread    
    Thread tools Search this thread Display Modes  
07-26-2008, 05:07 AM
#1
discotank.com is offline discotank.com
Status: I'm new around here
Join date: Jul 2008
Location:
Expertise:
Software:
 
Posts: 5
iTrader: 0 / 0%
 

discotank.com is on a distinguished road

  Old  MySQL Database organization question

I know my PHP but I am new at databases. I wanted to know how you would organize a database of users for an app that is supposed to hold a lot of information per user.

For example, if every user has a bunch of clusters of data that need to be stored, and they can always add more so it needs to be dynamic. What would your organization be for this?

Is this correct?
A table holds all users, and every user gets a table of their clusters?

07-26-2008, 05:14 AM
#2
cpf is offline cpf
cpf's Avatar
Status: I'm new around here
Join date: Dec 2007
Location: Canada
Expertise:
Software:
 
Posts: 23
iTrader: 0 / 0%
 

cpf is on a distinguished road

Send a message via MSN to cpf Send a message via Skype™ to cpf

  Old

A table per user is a plan for disaster. Hard to manage, messy, hack-ish, etc.
The way to do this I'd say is to take the id field of the user (you have one, right?), and use it as a reference/link to that user in another table that contains the data.
This way it is dynamic, easy to work with (just do a SELECT * FROM `userclusters` WHERE `userID`='$uid'), and effective to manage. Obviously this is overkill for things like email and MSN contact name, but is needed for things where, say, users upload and store files to a website.

07-26-2008, 05:26 AM
#3
discotank.com is offline discotank.com
Status: I'm new around here
Join date: Jul 2008
Location:
Expertise:
Software:
 
Posts: 5
iTrader: 0 / 0%
 

discotank.com is on a distinguished road

  Old

is it okay to have a table that big though? and thanks much for your help.

07-26-2008, 05:41 AM
#4
cpf is offline cpf
cpf's Avatar
Status: I'm new around here
Join date: Dec 2007
Location: Canada
Expertise:
Software:
 
Posts: 23
iTrader: 0 / 0%
 

cpf is on a distinguished road

Send a message via MSN to cpf Send a message via Skype™ to cpf

  Old

I'd have to look into it, but theoretically databases are designed for relatively few tables, but those tables having massive datasets in them (I've got a 16mb mysql table that handles just fine).

07-26-2008, 05:45 AM
#5
discotank.com is offline discotank.com
Status: I'm new around here
Join date: Jul 2008
Location:
Expertise:
Software:
 
Posts: 5
iTrader: 0 / 0%
 

discotank.com is on a distinguished road

  Old

great thanks!

07-26-2008, 03:40 PM
#6
NickReffitt is offline NickReffitt
NickReffitt's Avatar
Status: Junior Member
Join date: Feb 2008
Location: Kent, UK
Expertise:
Software:
 
Posts: 68
iTrader: 0 / 0%
 

NickReffitt is on a distinguished road

Send a message via MSN to NickReffitt Send a message via Yahoo to NickReffitt Send a message via Skype™ to NickReffitt

  Old

You should be looking to keep your database fairly simple in structure to condense your scripts so they are also easy to understand.

07-28-2008, 11:31 PM
#7
ThinkMinds is offline ThinkMinds
ThinkMinds's Avatar
Status: I'm new around here
Join date: Jul 2008
Location: Toronto, Canada
Expertise:
Software:
 
Posts: 19
iTrader: 0 / 0%
 

ThinkMinds is on a distinguished road

  Old

Hi,

In general putting everything into one table is not good database design. Personally, I like my databases to be rather normalized (i.e. do not contain redundant data, contain tables with data only specific to the context of the table etc etc).

If you go here: http://dev.mysql.com/doc/refman/5.0/en/full-table.html it will tell you what the limits are on a table.

It really depends on what you are storing in that data - but also keep in mind that the larger the table size, the longer it will take to search. If you have a set of tables that is logically designed than you are using a "divide-and-conquer" approach when querying your database, which would be faster than looking through one single table with tons of data.

Like cpfx.ca said though, a table per user is not a good approach, what you could have however is a table of users, clusters and user_clusters (which would link up the user to their cluster). This way, the users table contains only info pertaining to users, clusters contain only the blobs of data and user_clusters maps each user to one or more clusters (or you can even map one cluster to many users) - sky is the limit

Good luck!

Mike

07-29-2008, 04:04 AM
#8
infinivert is offline infinivert
infinivert's Avatar
Status: Junior Member
Join date: Jul 2008
Location: Abilene TX
Expertise: Design, PHP, JS, HTML5, CSS3
Software:
 
Posts: 37
iTrader: 0 / 0%
 

infinivert is on a distinguished road

Send a message via AIM to infinivert

  Old

Good advice above. The way I think about it goes something like this:

OK, I've got a bunch of users, and every user has a bunch of attributes. Some of those attributes can only occur one at a time (things like userID, first name, last name, username, password, etc.) Those can be listed as fields in a single table with no problems.

Users may have variable numbers of other attributes, though. For example, every user on this forum has a different number of posts. So rather than building a table of posts for each user, you build one table called Posts and one of the fields contains the ID of the user who wrote the post. In this way, by using 2 tables, a single user can be related to any number of posts.

There may be other instances when the flexibility needs to go both ways. I ran into this when building a CMS recently. A user may have permission to edit any number of pages, and a single page may need to be edited by any number of users. In a case like this, I build 3 tables: 1 for Users, 1 for Pages, and 1 for Permissions. In the permissions table you have 3 fields: A Permission ID, a Page ID that references the Pages table, and a User ID that references the Users table.

There are probably occasionally instances where a more complicated set-up is needed, but I'd say one of these scenarios will take care of you 99% of the time.

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed