Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase 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 Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old January 15th, 2008, 04:40 AM
nhek nhek is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 1 nhek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 36 sec
Reputation Power: 0
Question Database design - too many columns in a table?

Hi,
I would like to ask a question regarding correct database design
I am just a network admin and I am about to hack a simple database for our accountants
(we are a small company, so by "network admin" means "the one who does everything with computers :))

I have a table specification from our accountants - they want to store about 300 or so different number values for each customer and year...
these are just some financial data - each number represents a value of different financial indicator - they (at least I was told so) don't depend on each other

so the structure might look like this:

create table fin_data (
id_customer int not null,
year int not null,
data_value1 int,
data_value2 int,
data_value3 int,

....
data_value300 int)

now these value fields doesn't have any relations between each other, so basicly there might not be a need to separate them into different tables - on the other hand I really hate the idea, that I have a table with 300+ columns, so I was thinking about some kind of structure that would break down each row of this huge table into separate fields, so the table would only have 4 columns, something like this:

table field:
- id_customer
- year
- id_field_type (would describe which of the 300 indicators this one is
- field_value

However this structure would probably make writing a query a real pain - at least I can't think of an elegant solution on how to
retrieve data, so that original 300+ values per row appear e.g. when they will want to query such database in excel...

So, please, someone experienced - should I go with the 300+columns mega table, or try to break it down, in which case, what would be the easiest way to get the data into rows?

I hope my description is clear, if not, please do ask I will try to clarify :).

Thank you very much for any advice in advance.

Reply With Quote
  #2  
Old January 15th, 2008, 08:13 AM
cwf's Avatar
cwf cwf is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 343 cwf User rank is Private First Class (20 - 50 Reputation Level)cwf User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 8 m 34 sec
Reputation Power: 2
The proper design to use is the second method.

Quote:
300 or so different number values


The second method does not care exactly how many different values there are and it does not take up any storage space for any unused values. The first method would either require you to create the maximum number of columns or you would need to modify the table any time you need to add more columns.

The column with the "year" should actually be a DATETIME data type, so that you can query data for any previous time period.

If we assume you are talking about using mysql, the "basic" query to get all the data for any customer for the current "year" would simply be -

Code:
SELECT * FROM your_table WHERE id_customer = 123 AND
YEAR(your_datetime_column) = YEAR(NOW()) ORDER BY id_field_type


(assuming that the id_field_type is the order you want the rows to be returned as.)

Reply With Quote
  #3  
Old January 23rd, 2008, 08:48 AM
lig's Avatar
lig lig is offline
"Forum Nazi"
Codewalkers Demi-God (4500 - 4999 posts)
 
Join Date: Apr 2007
Location: Jacksonville, Fl
Posts: 4,719 lig User rank is Private First Class (20 - 50 Reputation Level)lig User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 4 m 29 sec
Reputation Power: 6
Be honest with yourself. Is this something that will be used often and grow over time or is it something that will only be used occasionally and never be added to. If the first - your second design is better. harder to query against - but much easier to scale over time.

If the second - the you can go with your first design and pray it never becomes more then it is originally intended. Lower normalization makes things easier to query but can become a pain as things grow.

Also depending upon how you want do things - you can make a views of the most commonly requested info that the users can query on with their excel. This will allow you to give them all the info they need in one place to make their queries easier and help up the speed of those queries. But still have the base data for anything more advanced or comprehensive.
__________________
life is a game.... Have fun
-----------------------------
http://www.phpwomen.org
strength in unity

PHPCommunity IRC
#phpc on freenode

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Database design - too many columns in a table?


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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway