Sql-server – SQL Server 2008 – How to schedule a copy of view to another database

sql server

I am a SharePoint admin and need to copy the log data in database to another temp database for analysis. The data is stored in a view ([WSS_Logging].[dbo].[RequestUsage]). There is a column [LogTime] on the view and any row older than 14 days will be discarded.

I would like to setup a daily schedule job to copy all records one day before to a temp database. I estimate there will be 1GB data daily. May I have your suggestion the best way to achieve this? If possible, please introduce method to check against the copying have not lost any row during the copy, too.

SQL Server is not my professional area. Any help is appreciated. Thanks.

Best Answer

Moving 1GB is not a trivial operation, though not a scary one either. A simple INSERT .. SELECT would have too much impact on the running server. Batching so only n-thousand rows are moved at a time would be better. 'n' can be tweaked to the idiosycracies of your particular system. Better still would be a dedicated ETL package. You'll need a SQL Server developer to help you with that, most likely. If it is important that you never miss a row be sure to build reconciliation into whatever solution you adopt.

Be careful using a datetime to determine whether a row should be copied or not. Times have to rounded to the resolution of the column holding them. It is therefore possible that a new row is rounded down and missed by the next extraction. It sounds like you will be copying data that is 13 days old so will not be at risk.