Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have two databases with same table structures. One database is live database and it is very huge. So that I want to delete 7 days older data but before that I want to take a differential backup and restore it to other database and retain the last data.
Posted
Comments
Oshtri Deka 11-Oct-12 2:46am    
Googlable, but nonetheless very good question.

SQL Job will be good choice to implement these scenarios. Now To track the 7 days older date there may be many approaches. One i am writing which i've seen in some applications. you can have a column with 'Created Date'/'Updated Date' and on creating/modifying just update this column.
 
Share this answer
 
As Peeyush Pachaori has suggested I would too use Sql Agent's Job for this task.
In order to delete records from tables you must keep track of insertion/update for every record, cascade deletion could be handy as well.

deletion code:
SQL
DELETE FROM MyTable
WHERE LastUpdateTime < @requiredDate


code for diff backup:
SQL
BACKUP DATABASE [DBName] TO  DISK = N'Backup_Path'
WITH  DIFFERENTIAL , NOFORMAT, NOINIT,
NAME = N'DBName-Differential Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO


I hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900