Jump to content

table structure...easy/lazy way vs proper way?


galvin

Recommended Posts

I am still trying to fully comprehend table normalization and I'm not asking anyone to explain it bc it's not a simple thing to explain.

 

But I'm working on a football website that tracks players stats each week (catches, yards and touchdowns) and it seems like setting it up this way would make it the easiest (maybe laziest?) to retrieve data to display wherever I want...

 

tablecalled players with these fields:

playerid

playerfirstname

playerlastname

week1catches

week1yards

week1touchdowns

week2catches

week2yards

week2touchdowns

...

and so on 17 times till...

...

week17catches

week17yards

week17touchdowns

 

I know that is likely making most of you want to puke but if doing it this way makes it extremely easy to pull this info for display on the site, why is it so wrong?  Is the problem that it's much slower than what I THINK is the proper way, ie...

 

table called players with these fields:

playerid

playerfirstname

playerlastname

 

AND

 

table called stats with these fields:

playerid

week

catches

yards

touchdowns

 

Again, not asking for an explanation of normalization, just if anyone has any quick reasons why the first way is as god awful as I fear it is, I'd appreciate the knowledge. 

 

Thanks!

 

Link to comment
Share on other sites

makes it extremely easy to pull this info for display on the site

 

 

it doesn't even do that, since you either have to hard-code each field reference or build a dynamic reference to access the incrementing field names. what if you are trying to get the total of any field, i.e. total yards? you have to write a bunch of php code or a verbose query listing all the relevant fields to do it.

 

by normalizing the data, you can do a simple SUM() in a query to get the same result.

  • Like 1
Link to comment
Share on other sites

no case that i can think of.

 

even if you only have two same meaning fields spread out in a row, it results in more code to find or manipulate the correct piece of data.

 

this boils down to the granularity of the data. normalized data stores each piece of same meaning data in its own row. as a result, you can easily find or manipulate any amount of the data, be it one piece, a specific sub-set of the data, or all the data.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.