Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically run a stored procedure on scheduler basis?

Tags:

sql-server

I want to execute a stored procedure automatically at every night. How can I do it. Please guide me with steps to achieve this target.

Thanks in advance.

like image 597
Tripati Subudhi Avatar asked Aug 28 '12 11:08

Tripati Subudhi


People also ask

How do I automatically execute a stored procedure in SQL?

In Object Explorer, connect to an instance of the SQL Server Database Engine, expand that instance, and then expand Databases. Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure.

Can a stored procedure run on a schedule?

You can use the administrative task scheduler to execute stored procedures at a specific time. You must first define a task for the stored procedure execution. Then, when the specified time or event occurs for the stored procedure to run, the administrative task scheduler calls the stored procedure.

How do I schedule a SQL query to run daily?

In the 'Steps' window enter a step name and select the database you want the query to run against. Paste in the T-SQL command you want to run into the Command window and click 'OK' . Click on the 'Schedule' menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).


1 Answers

You can create a job with the SQL Server Agent.

enter image description here

Right-click on the Jobs folder to open the menu, select New Job:

enter image description here

When you create a new job a window will open and you will provide the details of you job that you want to create. Including:

  • Name - in the General tab
  • Steps - can run a SQL script, SSIS package, stored procedure
  • Schedule - recurring, weekly, daily, etc. at the frequency that you pick.

Here is a Step by Step by Guide to creating a SQL Job

like image 117
Taryn Avatar answered Sep 24 '22 12:09

Taryn