The company has an old project because directly to the terminal shot pictures in the form of binary saved to the database, the database is larger so need to often delete these redundant data, manual removal time and effort, project leader let me turn these operations into automatic, do once a day, only the last two months of image data. Consulted the relevant information, found a solution, here to make a record, so that people with the same needs and their own access.
Now we're going to show you how to set up a timed task with a very simple example: we have an employee table and we add a piece of data to it on a regular basis. An example of how to use the job task of SQL Server to periodically delete data is to learn how to do this:
Table structure:
1. Turn on the SQL Server Agent service
Using a job requires support for the SQL Agent service and needs to be set to start automatically, otherwise your job will not be executed.
The following steps open the service: Start-->>> run-->>> enter "Services.msc"-->>> enter the service, turn on the SQL Server Agent service, and set to Automatic.
:
2. New Job
Click "SQL Server Agent", "right click Job", select "New Job"
3. Set the name and description of the new job
4. Set up a task's execution steps
Select the "Step" option and click "New" to add the first step: Insert the data and click "OK".
We can also go on to create new steps and do more in the Advanced options in the dialog box of the new step. ()
5. Set up the execution plan
Select schedule options, new schedule
Configure the direct schedule as needed:
Click OK to make sure our plan is complete: the statement that inserts the data starts on March 8, 2012, executes hourly, and in the new Job dialog we have the option not set, but this is not necessary, you can do the relevant settings according to the specific situation.
To set a timer task by using SQL Server 2005 jobs