I do apologize if my question sounds too easy for some of you. I'm new to SQL Server and I'm desperately in need of an advise. I did my research, but I'm still unsure how to proceed as all articles I read about it seem a bit too generic.
My task is to keep table ABC (on server 1) free of records older than 3 months. Records, which are older than 3 months should be automatically moved to the table ABC_ARCHIVE on server 2. Just coping and deleting records is not a big deal, but I'd like to automatically check that the records are already on Server 2 before deleting them from the server 1.
I thought about using a query, which I will run in SSIS package, which in turn will be run in a SQL Server Agent job. If you think that I should go differently about it, please let me know. I prefer to avoid involving any unneeded components.
To select records older than 3 months I need something like the query below:
Select *
From ABC
WHERE [CreateDate] <= DATEADD(mm, -3, GETDATE())
then the same one with "delete" in place of "select" to delete them.
What do I write in between these two queries to make sure that the rows were indeed transferred before deleting them? How to automatically check that the records are already on Server 2 before deleting them from the server 1? If its impossible to do it this way, could you please suggest alternative solution?
I'm using Enterprise x64 edition and my accounts has sysadmin privileges. I am very comfortable with creating jobs in SQL Agent and moderately comfortable with SSIS(tips will be very welcome).
I'll be very grateful for any tips and suggestions. Thank you in advance!
You use the OUTPUT clause for operations like this:
Here is a working example using table variables: