473,396 Members | 1,813 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,396 software developers and data experts.

summing from multiple tables

We recently added a new database at the company. It has only one
purpose - to hold massive amounts a daily data generated by telephone
calls on a network.

The amount of data was so large (several gigabytes a day) that the guy
who set up the database creates a new table for it each day.

His thinking was that if we only need to query one day's worth of data
then it would be a lot faster to query a table with one day's data
than having to query many days of data in one table.

I see his reasoning. Any comments or alternatives to this scheme
would be appreciated.

Here's the question though...I'm writing a front end for this and was
wondering if the most efficient way to query and sum data across
multiple tables (days) is in the form of the following statement.
Suppose three days of worth of data are wanted:

select sum(ET) from (select sum(vc_elapsed_time) AS ET from
switch2030608 where init_cell_info_cell = 196 union all select
sum(vc_elapsed_time) as ET from switch2030609 where
init_cell_info_cell = 196 union all select sum(vc_elapsed_time) as ET
from switch2030610 where init_cell_info_cell = 196 ) t

In my front end, based on user input, I plan to keep extending this
statement with more union alls. Is this the best way to implement the
goal of this query?

-David
Jul 20 '05 #1
1 5861
wireless (wi*********@yahoo.com) writes:
The amount of data was so large (several gigabytes a day) that the guy
who set up the database creates a new table for it each day.

His thinking was that if we only need to query one day's worth of data
then it would be a lot faster to query a table with one day's data
than having to query many days of data in one table.
Maybe. With a clustered index on the date, this could be avoided. But
with this large amount of data, this starts to make some sense. Not
the least if you want to remove old data after a week or a month.
Much easier to drop a table, than to delete several GB in one statement.
Here's the question though...I'm writing a front end for this and was
wondering if the most efficient way to query and sum data across
multiple tables (days) is in the form of the following statement.
Suppose three days of worth of data are wanted:

select sum(ET) from (select sum(vc_elapsed_time) AS ET from
switch2030608 where init_cell_info_cell = 196 union all select
sum(vc_elapsed_time) as ET from switch2030609 where
init_cell_info_cell = 196 union all select sum(vc_elapsed_time) as ET
from switch2030610 where init_cell_info_cell = 196 ) t

In my front end, based on user input, I plan to keep extending this
statement with more union alls. Is this the best way to implement the
goal of this query?


You should look into partitioned views. A partitioned view is basically
a view with a UNION ALL clause that combines the tables. You should also
add some constrataints to the table, so that SQL Server knows where the
data is.

The tables would need to have a date column, even if this is redudant
for a single table, and this column would be like:

CREATE TABLE switch_20030911
(date datetime NOT NULL
CONSTRAINT default_20030911 DEFAULT '20030911',
CONSTRAINT check_20030911 CHECK (date = '20030911'),
-- other columns follow here.

The nice thing is if you query the view for a certain date, SQL Server
will only touch the table with that date.

Obviously, the view would need to be redefined each day, but that is
a cheap operation.

Now, I should put in a big fat disclaimer here: I have never used
partitioned views myself. So rather than giving all details here, I
encourage you to check out the topic futher in Books Online.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

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

Similar topics

9
by: Yaroslav Bulatov | last post by:
I made an array of 10 million floats timed how long it takes to sum the elements, here's what I got (millis): gcc -O2: 21 Python with numarray: 104 Python with Numeric: 302...
0
by: Marco Alting | last post by:
Hi I have three levels of cost items, like the following: TOP_LEVEL SECOND_LEVEL cost_item1 cost_item2 etc... TOP_LEVEL2
1
by: Ciar?n | last post by:
I am trying to check a list (MyList) against another List (SupplierList). I want sum the Qty's of UniqueID on MyList and extract the sum of the same UniqueId's on SupplierList. BTW There are more...
7
by: Hank | last post by:
I have a report-summing problem using Access 2000. When a section runs over the end of the page, sometimes a detail gets picked up twice. Example: Customer Header XYZ Company Detail Section...
13
by: Don Sealer | last post by:
I have about 40 different defects I'm tracking. I'd like to have all of these defects totaled individually, both by month and by year. I'd like to show these results in a report. I know I could...
4
by: dancole42 | last post by:
So I have an invoicing database based on two main forms: Orders and OrderLines. Orders has fields like: OrderID BillingMethod OrderDate CreditCard CCExp OrdSubTotal ShippingCharge
5
by: tulikapuri | last post by:
Hello Friends, I am building a report in Access 2003 and the data comes from two different tables which are linked with primary key. One of the tables has internal data and the other has external...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
7
by: lethek39 | last post by:
Hey I have been trying to figure out how to sum rows and columns in a matrix square. I also have been trying to get the program to list the numbers of the diagonal in the matrix. So far this is the...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.