爱在莫斯科 发表于 2016-11-12 06:54:54

[MSSQL]sql 存储过程定时执行方法

-- 创建存储过程,每隔 30 秒钟运行一次。create procedure usp_daemonasset nocount onwhile 1=1beginupdate set type=0 where data<getdate();delete from where userid in (select userid from where type=0);waitfor delay '00:00:30'endgo-- 将 sql server 实例设置为“在实例启动时扫描可自动执行的存储过程”sp_configure 'show advanced options',1reconfiguresp_configure 'scan for startup procs',1reconfiguresp_configure 'show advanced options',0reconfigure-- 将存储过程设置为“实例启动时自动执行”sp_procoption 'usp_daemon','startup','true'  
页: [1]
查看完整版本: [MSSQL]sql 存储过程定时执行方法