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.
<br data-filtered=
"filtered"
>
if
exists(
select
name
from
sysobjects
where
name=
‘StaySchoolNum‘
and type=
‘p‘
)
drop proc StaySchoolNum
go
create proc StaySchoolNum
as
declare @init
int
,@totle
int
select
@init=count(*)
from
dbo.dic_vehicle
where
parent_id=1
if
@init=0
begin
insert
into
dic_vehicle values(1,1,
‘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