September 7, 2013 at 2:56 am
Hello,
I have a production database which is loaded regularly via SSIS packages.
In the database there are etl (schema) tables which are loaded by every load with all the info, so that they can be used as a backup at some point.
Now I want to have the full history of the etl tables only on my local server (which is a copy of the production) and to keep only the last three months on production.
Do you have an idea how to create this SSIS?
Thanks.
September 12, 2013 at 2:26 pm
I'm not sure I'm fully understanding what you're attempting, but are there any datetime columns in your data you can use to extract out three months?
September 16, 2013 at 3:45 pm
When you say three months, do you mean a rolling 93 days, or archive a month at the end of each month (i.e. have between 3 and 4 months on the PROD server).
Why do you only want recent data on the PROD server. If it is a performance issue then you should be looking at server configuration and indexing. If it is space or security then you should be looking at partitioning the database and limiting access to the older partitions.
September 18, 2013 at 2:29 am
Hello Veteran,
Thank you for the reply.
First it is a space issue and also design issue.
However what I need is to keep only the data from the last ~90 days.
September 18, 2013 at 9:19 am
So what we are looking at is a rolling delete process
My preference (for codeability) would be a sproc in the database that takes two arguments Tablename to be deleted and Days to Keep
The sproc would build a dynamic SQL statement to remove the records
NOTE the code below has not been checked, it is symantec rather than syntactic.
CREATE PROCEDURE dbo.uspDeleteOldData (@TableName nvarchar(50), @DaysToKeep int default = 90)
AS
DECLARE @SQL as nvarchar(max)
SET @SQL = N'DELETE FROM ' + @TableName + ' WHERE CreateDate <= ''' + cast(DateAdd(days,(@DaysToKeep * -1), getdate()) as nvarchar)
sp_executeSQL @SQL
I would then build an SSIS package that simply has a list of SQL tasks that calls the sproc for each table you need to clean up.
NOTE that you may end up with lots of sparsely populated index pages so you will need to clean up the database on a regular basis to remove the unused space.
September 20, 2013 at 12:10 am
NOTE the code below has not been checked, it is symantec rather than syntactic.
I think you meant 'semantic', unless your solution is proposing an unorthodox anti-virus methodology 🙂
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply