SQL Stored procedure to delete data older than 1 years from the database. Deletion should be performed in specified month after every 1 year
Loading
SQL Stored procedure to delete data older than 1 years from the database. Deletion should be performed in specified month after every 1 year
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Janarthanan SPosted Jun 2, 2023, 2:33 AM
To execute SQL code
Rajkiran SwainPosted Jun 1, 2023, 6:27 PM
Amit MohantyPosted Jun 1, 2023, 5:52 AM
To run a stored procedure in a specified month after every 1 year, you can use a combination of SQL Server Agent and a scheduled job.
Open SQL Server Management Studio and connect to your SQL Server instance.
Expand the "SQL Server Agent" folder in the Object Explorer.
Right-click on the "Jobs" folder and select "New Job". This will open the New Job dialog box.
In the "General" tab of the New Job dialog box, provide a name for the job in the "Name" field.
In the "Steps" tab, click on the "New" button to create a new step for the job. This will open the New Job Step dialog box.
In the New Job Step dialog box, provide a name for the step in the "Step name" field.
In the "Type" section, select "Transact-SQL script (T-SQL)" as the type.
In the "Database" field, select the appropriate database where your stored procedure exists.
In the "Command" field, enter the code to execute your stored procedure. Here's an example:
Click on the "OK" button to save the job step.
In the "Schedules" tab of the New Job dialog box, click on the "New" button to create a new schedule for the job. This will open the New Job Schedule dialog box.
In the New Job Schedule dialog box, configure the schedule as follows:
Click on the "OK" button to save the job schedule.
Review the job settings in the "Notifications", "Targets", and "History" tabs as per your requirements.
Click on the "OK" button to create the job.