First of all, I want to say, I really is slag, a this thing to get a half-day, forget, directly into the subject bar.
The first step:
Write the stored procedure first.
You have two tables, you build it yourself.
If exists (select name from sysobjects where name= ' stayschoolnum ' and type= ' P ') drop proc stayschoolnum Go create proc stayschoolnumasdeclare @init int, @totle intselect @init =count (*) from Dbo.dic_vehicle where parent_id=1 if @init =0 begin INSERT into dic_vehicle values (0 ') end ELSE BEGIN Select @totle =count (*) from Dbo.tb_vehicle_data v where v.szingatecode<> ' and v.szoutgatecode= ' update dic _vehicle set [email protected] where parent_id=1 end
Step two: Set up a timed job
1. Open the Local data connection and locate the SQL Server Agent in the left explorer (at the bottom)
2, "new" a job
3, in the "General" to fill in the name can be explained to see personal habits
4. Open "Step", click "New", Fill in "Name", select "Database", fill in the command blank with T-SQL statement, then point analysis.
5. Open "Schedule", click "New", set the schedule you want, then save.
6, click on "SQL Server Agent", right-start, that is, timed job start.
7. If you want the scheduled job to start automatically, find SQL Server agent (MSSQLSERVER) in the service, set to "automatic" mode
Step three: Generate scripts for scheduled jobs
Method 1, click the job under SQL Server agent, select the job you created--right-write the job script--create to, and then copy the scripting language
Method 2, found that bloggers wrote this (manage -sql Server Agent -Jobs (right mouse button )-All Tasks -Generate SQL script -Save to a SQL file under [Page] ), I didn't find it.
Found this blogger write good, recommended: http://www.cnblogs.com/shuang121/archive/2011/11/10/2244482.html
SQL Server timed jobs, scheduled execution of stored procedures