Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Friday, March 9, 2012

Keeping track of last time of extract

I am building an SSIS package in which I extract data from a number of transaction tables. The rows in each transaction table contain a timestamp. I would like to do the following.

* Every time I extract rows from a table I want to extract only the records added since last extract (no rows are modified or deleted - only added)
* In the extract process I want to find the maximum timestamp in a given table. This timestamp should be stored and updated in a table on the SQL Server. This way, the next time the extraction process is run only "new" rows are extracted

How would you go about doing this in SSIS? I have thought of the following approach, but I am unsure whether it is too cumbersome.

* A package variable is defined for each of the transaction tables
* A series of Execute SQL Tasks populates each of these variables with the timestamps from the table in SQL Server
* A series of data flow tasks extract the data (using the variables populated above in the WHERE-condition). Contained in the data flow tasks is a script component which records the maximum timestamp extracted and places this in yet another package variable (I am unsure how to do this, by the way...)
* A series of Execute SQL Tasks updates the table in SQL Server with the new timestamps

How would you do this?

Thanx! SmileThis is how I'd do it. It isn't particularly a SSIS solution...just the way I'd do it!

Have 2 values stored in a table called (e.g.) tblConfig. They are:
LastExtractDate
ThisExtractDate

Step 1) UPDATE tblConfig SET LastExtractDate=ThisExtractDate, ThisExtractDate = GETDATE()

Step 2) SELECT * FROM <source_table> WHERE <some_tstamp_value> >= LastExtractDate AND <some_tstamp_value> < ThisExtractDate> (this would be inside a data-flow source adapter)

OK, column names may change etc...but you get the idea!!!

-Jamie|||Very nice... And simple. Smile One question though (for doing this in SSIS): Do you enlist the two tasks in the same transaction (using a sequence container for instance) so that if the data flow tasks fails, you will not "miss" any rows on the next run?

/Michael|||

Reckless wrote:

Very nice... And simple. Smile One question though (for doing this in SSIS): Do you enlist the two tasks in the same transaction (using a sequence container for instance) so that if the data flow tasks fails, you will not "miss" any rows on the next run?

/Michael

Yeah. Good idea!

-Jamie|||Hi, folks:
Exactly how do we do this. Do we do a OLE data source > something > OLE data destination. Thanks in advance.|||

Al_chan wrote:

Hi, folks:
Exactly how do we do this. Do we do a OLE data source > something > OLE data destination. Thanks in advance.

Hi Al,
Step 1 I would do in an Exec SQL Task.
Step 2 most likely in a data flow - yes, using an OLE DB Data Source.

-Jamie

Friday, February 24, 2012

Keep only X # of backups when appending to BU file

Using SQL Server 2005 STD, is there a way to create a maintance plan to
backup the database, appending to a file, but only keeping the last X number
of backups?
I would like to keep 4 full backups at a time. When the 5th backup occurs, I
would like the first to be deleted.
I've seen options like this in 3rd party backup tools, but is there a way to
do this natively w/ SQL Server?Have a look at the expire parameter of the backup command. From
http://msdn2.microsoft.com/en-us/library/ms187510.aspx
a.. To have the backup set expire after a specific number of days, click
After (the default option), and enter the number of days after set creation
that the set will expire. This value can be from 0 to 99999 days; a value of
0 days means that the backup set will never expire.
The default value is set in the Default backup media retention (in days)
option of the Server Properties dialog box (Database Settings Page). To
access this, right-click the server name in Object Explorer and select
properties; then select the Database Settings page.
Hilary Cotter
Director of Text Mining and Database Strategy
RelevantNOISE.Com - Dedicated to mining blogs for business intelligence.
This posting is my own and doesn't necessarily represent RelevantNoise's
positions, strategies or opinions.
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Dan" <Dan@.discussions.microsoft.com> wrote in message
news:DEA2E6D1-DB67-42F7-8406-E37EB553AEA9@.microsoft.com...
> Using SQL Server 2005 STD, is there a way to create a maintance plan to
> backup the database, appending to a file, but only keeping the last X
> number
> of backups?
> I would like to keep 4 full backups at a time. When the 5th backup occurs,
> I
> would like the first to be deleted.
> I've seen options like this in 3rd party backup tools, but is there a way
> to
> do this natively w/ SQL Server?|||If every backup goes to the same file, then the answer is no. There
is no way for SQL Server to drop old backups from the front of the
file. The solution is for each backup to go to an individual file.
Roy Harvey
Beacon Falls, CT
On Tue, 19 Sep 2006 18:34:01 -0700, Dan
<Dan@.discussions.microsoft.com> wrote:
>Using SQL Server 2005 STD, is there a way to create a maintance plan to
>backup the database, appending to a file, but only keeping the last X number
>of backups?
>I would like to keep 4 full backups at a time. When the 5th backup occurs, I
>would like the first to be deleted.
>I've seen options like this in 3rd party backup tools, but is there a way to
>do this natively w/ SQL Server?