陋室铭
永远也不要停下学习的脚步(大道至简至易)

 

具体步骤:
企业管理器
--管理
--SQL Server代理
--右键作业
--新建作业
--"常规"项中输入作业名称
--"步骤"项
--新建
--"步骤名"中输入步骤名
--"类型"中选择"Transact-SQL 脚本(TSQL)"
--"数据库"选择执行命令的数据库
--"命令"中输入要执行的语句:

 

下面是备份数据库,并且删除15天以前备份的版本

DECLARE @strPath NVARCHAR(200)

DECLARE @strPathDel NVARCHAR(200)

set @strPath = convert(NVARCHAR(19),getdate(),112)

set @strPathDel = convert(NVARCHAR(19),getdate()-15,112)

set @strPath = 'D:\备份\服务器自动备份\' +'JSOA2010' +@strPath + '.bak'

set @strPathDel = 'del '+'D:\备份\服务器自动备份\' +'JSOA2010' +@strPathDel + '.bak'

BACKUP DATABASE [JSOA2010] TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10,

NOFORMAT

exec master..xp_cmdshell @strPathDel


--确定
--"计划"项
--新建计划--"名称"中输入计划名称
--"计划类型"中选择你的作业执行安排--定为每天计划一次,时间为18:40即可
--如果选择"反复出现"
--点"更改"来设置你的时间安排


然后将SQL Agent服务启动,并设置为自动启动,否则你的作业不会被执行

设置方法:
我的电脑--控制面板--管理工具--服务--右键 SQLSERVERAGENT--属性--启动类型--选择"自动启动"--确定.

 

如果报“SQL Server 阻止了对组件'xp_cmdshell' 的过程'sys.xp_cmdshell' 的访问-12-30 13:35”错误

解决方法:执行下面的语句

-- To allow advanced options to be changed.

EXEC sp_configure 'show advanced options', 1

GO

-- To update the currently configured value for advanced options.

RECONFIGURE

GO

-- To enable the feature.

EXEC sp_configure 'xp_cmdshell', 1

GO

-- To update the currently configured value for this feature.

RECONFIGURE

GO

 

posted on 2007-06-14 15:05  宏宇  阅读(2201)  评论(0编辑  收藏  举报