473,378 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Database Design Q: Many Rows or Many Tables?

Hi there

I'm in the planning stages of creating a database, and I have two options
here. Which makes more sense, and/or provides better performance for
queries - a single table with hundreds of thousands of rows, or many
tables with less rows?

GOAL:
Recording information about buildings, storey by storey. Basically I
will be recording six bits of information about each storey in each
building.

SETUP:
There will be one table for Buildings for sure. The big question is about
how I should record those six details per storey.

OPTIONS:
A) One table that records building ID, storey number, and the six
measurements per row.
B) Six tables that record building ID, storey number, and the appropriate
measurement.
Eventually, there could be a few thousand buildings in the database, and
each building may have anywhere from 5 to 50 storeys. Not to mention that
"old information" is to be kept and archived as new information about
storeys is added.

This means with option A, I can expect to have a table of a few hundred
thousand rows.... (obviously i would index the BuildingID and Storey
Number). Sounds like a lot(!), but it means that I could retreive/select
information I need with one single query and no table joins.

If I go with option B, I can expect to have to do six table joins/queries
when retreiving information about one storey in one building, however
there will be less records to sift through.
Which is the better option to take, and why? By 'better', I am referring
to database performance/speed, updates and other future maintenance on
the database. All opinions welcome.

Thanks,
GM
,
Jul 20 '05 #1
7 2877
Good Man wrote:
Hi there

I'm in the planning stages of creating a database, and I have two options
here. Which makes more sense, and/or provides better performance for
queries - a single table with hundreds of thousands of rows, or many
tables with less rows?

GOAL:
Recording information about buildings, storey by storey. Basically I
will be recording six bits of information about each storey in each
building.

SETUP:
There will be one table for Buildings for sure. The big question is about
how I should record those six details per storey.

OPTIONS:
A) One table that records building ID, storey number, and the six
measurements per row.
B) Six tables that record building ID, storey number, and the appropriate
measurement.
Eventually, there could be a few thousand buildings in the database, and
each building may have anywhere from 5 to 50 storeys. Not to mention that
"old information" is to be kept and archived as new information about
storeys is added.

This means with option A, I can expect to have a table of a few hundred
thousand rows.... (obviously i would index the BuildingID and Storey
Number). Sounds like a lot(!), but it means that I could retreive/select
information I need with one single query and no table joins.

If I go with option B, I can expect to have to do six table joins/queries
when retreiving information about one storey in one building, however
there will be less records to sift through.


Why would there be less rows with option B? With each scenario, you'll still
have one row per storey, surely? So in fact, option B will be a far larger
database, because you'll be storing each building ID and storey number six times.

Option A is far more sensible, because it'll be smaller, you won't have to do
any table joins, and the data is all in one place, which is easier to maintain
in the long run.

Oli
Jul 20 '05 #2
Oli Filth <ol*******@eatspam.coldmail.com> wrote in
news:r0**************@newsfe1-gui.ntli.net:
Why would there be less rows with option B? With each scenario, you'll
still have one row per storey, surely? So in fact, option B will be a
far larger database, because you'll be storing each building ID and
storey number six times.

Option A is far more sensible, because it'll be smaller, you won't
have to do any table joins, and the data is all in one place, which is
easier to maintain in the long run.


Hi... I left something out regarding my database design structure (option
A may actually record more than one row per story) but still you bring up
a good point - there will still be a similar number of total rows
regardless of which option I choose. Funny how I missed that :P

Thanks for your help... I suppose my real concern was making sure that
MySQL can go through several hundred thousand rows (what about
millions?), but I suppose it can if I have the required disk space and I
index my tables properly...

PS: Regarding indexing, do I just set up the table with an Index, or do I
need to index the table every month or so to make sure new records are
being indexed?

Thanks for the advice...

GM
Jul 20 '05 #3
Good Man wrote:
Thanks for your help... I suppose my real concern was making sure that
MySQL can go through several hundred thousand rows (what about
millions?), but I suppose it can if I have the required disk space and I
index my tables properly...

PS: Regarding indexing, do I just set up the table with an Index, or do I
need to index the table every month or so to make sure new records are
being indexed?

Thanks for the advice...

GM


Hi

I've never used a MySQL table with more than a few hundred records, but I guess
it still works fine with thousands or millions (just that queries will take much
longer).

If you set up a particular field in a table as an index, MySQL will
automatically handle indexing of new insertions. However, if you're frequently
deleting or altering existing records then the table becomes fragmented, so you
should run a "OPTIMIZE TABLE table_name" query every so often, which defrags the
table and re-sorts indexes.

If you're going to be running tables with hundreds of thousands of records, it'd
be well worth thinking about optimisations that you can use for your table
design and the way that you form queries. For instance, use fixed-length CHAR
strings rather than VARCHAR or TEXT. Try
http://dev.mysql.com/doc/mysql/en/My...imization.html for loads of stuff on
optimisation.

Hope this helps,
Oli
Jul 20 '05 #4
Good Man wrote:
Hi there

I'm in the planning stages of creating a database, and I have two options
here. Which makes more sense, and/or provides better performance for
queries - a single table with hundreds of thousands of rows, or many
tables with less rows?

GOAL:
Recording information about buildings, storey by storey. Basically I
will be recording six bits of information about each storey in each
building.

SETUP:
There will be one table for Buildings for sure. The big question is about
how I should record those six details per storey.

OPTIONS:
A) One table that records building ID, storey number, and the six
measurements per row.
B) Six tables that record building ID, storey number, and the appropriate
measurement.
Eventually, there could be a few thousand buildings in the database, and
each building may have anywhere from 5 to 50 storeys. Not to mention that
"old information" is to be kept and archived as new information about
storeys is added.

This means with option A, I can expect to have a table of a few hundred
thousand rows.... (obviously i would index the BuildingID and Storey
Number). Sounds like a lot(!), but it means that I could retreive/select
information I need with one single query and no table joins.

If I go with option B, I can expect to have to do six table joins/queries
when retreiving information about one storey in one building, however
there will be less records to sift through.
Which is the better option to take, and why? By 'better', I am referring
to database performance/speed, updates and other future maintenance on
the database. All opinions welcome.

Thanks,
GM
,


I would say that A is your best solution, but only if you are storing
one peice of information about the building, meaning Building ID. If
you want to store other peices of information about the building, like
street address, then you need a different approach... Option C.

Option C, requires 2 tables... Buildings, and Storeys. Tables are
listed below, and the fields are indented.

Buildings
BuildingID
Address1
Address2
City
... (other fields)
Storeys
BuildingID (FK to Building/BuildingID)
StoreyNumber
BitOfInfo1
BitOfInfo2
...
BitOfInfo6
John
Jul 20 '05 #5
B is better as long as you have a normalized data model.

Fewer tables mean less relational and mor records meaning more system
resources are used for each query

For large volumes do not use MySQL as it is not that scalable

Postgres is much faster

Good Man wrote:
Hi there

I'm in the planning stages of creating a database, and I have two options
here. Which makes more sense, and/or provides better performance for
queries - a single table with hundreds of thousands of rows, or many
tables with less rows?

GOAL:
Recording information about buildings, storey by storey. Basically I
will be recording six bits of information about each storey in each
building.

SETUP:
There will be one table for Buildings for sure. The big question is about
how I should record those six details per storey.

OPTIONS:
A) One table that records building ID, storey number, and the six
measurements per row.
B) Six tables that record building ID, storey number, and the appropriate
measurement.
Eventually, there could be a few thousand buildings in the database, and
each building may have anywhere from 5 to 50 storeys. Not to mention that
"old information" is to be kept and archived as new information about
storeys is added.

This means with option A, I can expect to have a table of a few hundred
thousand rows.... (obviously i would index the BuildingID and Storey
Number). Sounds like a lot(!), but it means that I could retreive/select
information I need with one single query and no table joins.

If I go with option B, I can expect to have to do six table joins/queries
when retreiving information about one storey in one building, however
there will be less records to sift through.
Which is the better option to take, and why? By 'better', I am referring
to database performance/speed, updates and other future maintenance on
the database. All opinions welcome.

Thanks,
GM
,

Jul 20 '05 #6
peter wrote:
B is better as long as you have a normalized data model.

Fewer tables mean less relational and mor records meaning more system
resources are used for each query


Doesn't apply in the OP's case, as his "option B" would literally be his "option
A" split into six.

i.e. For each storey:

"option A":

Table1: ID, StoreyNum, Data1, Data2, Data3, Data4, Data5, Data6
======

"option B":

Table1: ID, StoreyNum, Data1
======
Table2: ID, StoreyNum, Data2
======
Table3: ID, StoreyNum, Data3
======
Table4: ID, StoreyNum, Data4
======
Table5: ID, StoreyNum, Data5
======
Table6: ID, StoreyNum, Data6
======

As the OP has said that each storey will always be associated with six fields of
data, "option B" will take up more space, as ID and StoreyNum will be stored six
times each, *and* he'd have to do a six-table join for every query. There's no
way that's more efficient.

Oli
Jul 20 '05 #7
Good Man <he***@letsgo.com> wrote:
Which is the better option to take, and why? By 'better', I am referring
to database performance/speed, updates and other future maintenance on
the database. All opinions welcome.


I'd go with option A.

You didn't mention what you were searching on? If it's building ID or
storey ID, I wouldn't worry too much about table size. A modern database
should be able to search fixed keys from a table of millions in under
1 second. (where you get into trouble is like('%query%') )

The trick is in understanding how the database interprets the query. Fixed
index lookups are fast. Scanning rows of data is slow, so, try and minimize
rows you'll likely need to scan.

Don't be tempted to create indices w/out first populating the data, an index at the
wrong place & time can slow down the database (particularly inserts).

A good rule to follow is never, ever, EVER duplicate data. Ie, don't store
the same bit of information twice. For instance, don't copy stuff around, use
links: buildings AND stories.

buildings ======
bid | name | info that applies globally to same building

storey ======
sid | bid | info1 | info2 | info3 | info that applies only to storey.
Where building->bid = storey->bid.

That way, if you need to scan for a building name, you won't have to wade
through as much data. Once you find the building name, you can use it's
building ID (bid) to greatly minimize the rows from storeys that you'll be
scanning. (since 'bid' would be indiced and a FIXED query. (bid=code, NOT bid
like('%code%))

You've got: select * from storeys where bid=100 AND info2 LIKE('%str%')

The database should be smart enough to realize it can use it's bid index
to minimize the rows passed on to the like() clause. So, even if your stories
table has 50 buildings with 50 stories each, you'll only end up scanning
100 rows. (50 from the building table to get the BID from the name, and 50
from the stories table that were reduced from the index)

(Experience has shown me to hold off on indices until they are actually
required)

Jamie
--
http://www.geniegate.com Custom web programming
gu******@lnubb.pbz (rot13) User Management Solutions
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alessandro Ranellucci | last post by:
I'm building a PHP+MySQL application for a large website, with 100.000+ records in the main table, each one with a lot of dependencies in other SQL tables. Thus each page view requires many SQL...
2
by: Anders | last post by:
We need to create a lookup structure that can contain a flexible amount of attributes. We have discussed different design solutions for lookup-functionality, and come up with this suggestion: ...
4
by: Shane | last post by:
Hello, I'm pretty new to setting up databases, but so far I'm getting along swimmingly. But I have one question. I'm setting up a database for a client who wants to sell tickets to their theater...
3
by: Rushikesh | last post by:
I am designing a WEB BASED Accounting Software with ASP and SQL Server. For this I need some help for the Database design. My design is as follows. I)User table: User_id, UserName..... Users...
3
by: Bill MacLean | last post by:
-- Example Schema posted at end of message: --- For reporting purposes, I need to build a single comma delimited string of values from the "many" table of a database. The easiest way to see...
5
by: Don Vaillancourt | last post by:
Hello all, Over the years as I design more database schemas the more I come up with patterns in database design. The more patterns I recognize the more I want to try to design some kind of...
2
by: Cary | last post by:
This may reveal my poor programming skills, but here goes... I'm building a pricing tool for my business. I'm nearing the end of the project, and I've been asked to be able to save quotes in some...
5
by: A_M_IS | last post by:
Dear valuable experts, I truly hope than You can suggest for me Your ideas how to resolve design. I developing relative small Access VB tool, for single user use only. Access version 2003, but db...
12
by: grace | last post by:
i am wondering why my database retrieval becomes too slow...we set up a new server (ubuntu, breezy badger) machine where we transferred all our files from the old server.. Our new server uses Asus...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.