Forum Moderators: coopster
Im calling some data (names addresses and telephone numbers) from a mysql database.
The data is split into regions, lets say there are 200 entries per region. My question is, should I use one table to store all the data or should I break it up and have a seperate table for every region?
Table region
------------
index - name
1 - regionA
2 - regionB
Table user
------------
index - name - address - tel - user_region
1 - name1 - add1 - tel1 - 1
2 - name2 - add2 - tel2 - 1
3 - name3 - add3 - tel3 - 2
So that you can query for a specific region from the main table.
A quick search over the WebmasterWorld forums, or the entire Internet, will offer a great deal of discussion on the issue.
IMO it is far more important to separate SQL and code so that its easy to change SQL without having to go through too much code - this is good for changes from one DB to another as well as changes from poorly normalised to highly normalised tables. Changing underlieing queries is often difficult because it involves changing lots of code. If code is well structured then changing SQL to anything else that is functionally equivalent is a not a hard job.
Say in example above - why treat "region" to separate table only? Why not "names"? This could be even more useful because names linked to phones are more likely to change than region and address in which phone is located (could be mobile).
Lord Majestic said:in example above - why treat "region" to separate table only? Why not "names"? This could be even more useful because names linked to phones are more likely to change than region and address in which phone is located (could be mobile).
True. I would actually normalize the phone numbers as well ;)
One additional comment regarding the normalization route...
neo_brown said:tomda....
That is pretty much how I have it currently, just using one table and rather than a number for the region I am using the actual region name.
A couple of points regarding using an identifier rather than the region description as key when normalizing this database.
Downside is your admin scripts will have to be very disciplined and modify every instance of, eg., the author information in this table each time you change the author info.
You could have used triggers to do that (if your database supported them, which MySQL 4 aint), but getting into games with triggers may result in a major slowdowns related to updates of said normalised tables.
But lets not get too smart - for many small performance issues should be non-existant so long as you use good indices.