Solved

I need to download data from a huge table month wise

Posted on 2014-10-13
6
145 Views
Last Modified: 2016-02-11
Hi Experts,
I need to query a table from production which is huge for the past 6 months, I was suggested to query the prod table by month and load into 6 dev tables, not sure how I can do that?
Would SSIS be a good option? please suggest?
0
Comment
Question by:sqlcurious
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40377901
the request is quite unclear/unprecise...

the question is, what exactly you have as data and what you need as results...

one option might be to partition the (original) table, to start with:
http://msdn.microsoft.com/en-us/library/ms190787.aspx
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40378104
What is the clustering index on the original table?  If it is month/date[time], as it seems likely it should be, then querying by month makes sense.

I wouldn't load into 6 separate tables in dev.  Instead, just be sure to cluster the table by month/date[time].
0
 
LVL 13

Expert Comment

by:Russell Fox
ID: 40378132
See above for long-term solutions, but if this is a one-off project then this will create the new tables as it pulls data from the existing table:
SELECT * 
INTO Production201401
FROM dbo.Production
WHERE CAST([OrderDate] AS DATE) BETWEEN '1/1/2014' AND '1/31/2014'
GO
SELECT * 
INTO Production201402
FROM dbo.Production
WHERE CAST([OrderDate] AS DATE) BETWEEN '2/1/2014' AND '2/28/2014'
GO
-- Etc.

Open in new window

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40378143
No!  You never  use a cast a table column or use a function on one [if it can be avoided], as that disallows any index seek.  On huge tables that could be a major performance  issue, esp. when you run the command six times!

Also, literal date should always be coded as 'YYYYMMDD', as that format always works, regardless of SQL settings.

Finally, the best way to check dates/datetimes is with >= and <, not with between.

For example:

WHERE OrderDate >= '20140101' AND OrderDate < '20140201'
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40381412
Adding for emphasis, do not use BETWEEN for date ranges:

... the best practice with date and time ranges is to avoid BETWEEN and to always use the form:

WHERE col >= '20120101' AND col < '20120201'
This form works with all types and all precisions, regardless of whether the time part is applicable.
Itzik Ben-Gan

This applies to many databases using SQL. Also see: "Beware of Between"
0
 

Author Closing Comment

by:sqlcurious
ID: 40436356
Thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question