Ms Sql Server 基本管理脚本(3)

 /*

 *以下所有存储过程必须在MSDB上执行 
 */
 
use msdb
go
 
/*
 *操作员管理
 */
--创建
exec sp_add_operator 'xrjin', @netsend_address = '192.168.0.19'
 
--删除
exec sp_delete_operator 'test'
 
--更新
exec sp_update_operator 'xrjin', 'test', @netsend_address = '192.168.0.19'
 
--检索
exec sp_help_operator
 
/*
 *作业管理
 */
--创建
exec sp_add_job @job_name = 'test_job', @enabled = 1, @description = 'Test Job', @notify_level_eventlog = 1,
@notify_level_netsend = 1, @notify_netsend_operator_name = 'test'
 
--更新
exec sp_update_job @job_name = 'test_job'
 
--删除
exec sp_delete_job @job_name = 'test_job'
 
--检索
exec sp_help_job
 
--添加作业步骤
exec sp_add_jobstep @job_name = 'test_job', @step_id = 1, @step_name = 'shuke database', @subsystem = 'tsql',
@command = 'dbcc shrinkdatabase (northwind, 70)', @on_success_action = 1, @on_fail_action = 2
 
exec sp_add_jobstep @job_name = 'test_job', @step_id = 2, @step_name = 'backup database', @subsystem = 'tsql',
@command = [backup database northwind to disk = 'f:\aa.bak'], @on_success_action = 1, @on_fail_action = 2
 
--删除作业步骤
exec sp_delete_jobstep @job_name = 'test_job', @step_id = 2
 
exec sp_delete_jobstep @job_name = 'test_job', @step_id = 1
 
--更新作业步骤
exec sp_update_jobstep @job_name = 'test_job', @step_id = 1, @command = [dbcc shrinkdatabase (northwind, 65)]
 
--检索
exec sp_help_jobstep @job_name = 'test_job'
 
--添加作业服务器
exec sp_add_jobserver @job_name = 'test_job', @server_name = 'teacher-12'
 
--删除作业服务器
exec sp_delete_jobserver @job_name = 'test_job', @server_name = 'teacher-jin'
 
--启动作业
exec sp_start_job 'test_job'
 
--停止作业
exec sp_stop_job 'test_job'
 
--调度作业
exec sp_add_jobschedule @job_name = 'test_job', @name = 'test_job', @freq_type = 4, @freq_interval = 1, @active_start_time = 220000
 
--删除调度
exec sp_delete_jobschedule @job_name = 'test_job', @name = 'test_job'
 
--修改调度
exec sp_update_jobschedule @job_name = 'test_job', @name = 'test_job', @freq_type = 4, @freq_interval = 4, @active_start_time = 000000
 
--检索
exec sp_help_jobschedule @job_name = 'test_job'
 
 
/*
 *警报管理
 * @severity 警告级别
 * @include_event_description_in 错误消息如何发送 [0, 1, 2, 4] 默认0 = 无, 1 = 电邮, 2 = 呼叫程序, 4 = net send
 */
--创建
exec sp_add_alert @name = 'test_alert', @severity = 16, @enabled = 1, @notification_message = 'Test Alert',
@include_event_description_in = 4, @job_name = 'test_job'
--删除
exec sp_delete_alert 'test_alert'
 
--更新
exec sp_update_alert 'test_alert', @enabled = 0
 
exec sp_update_alert 'test_alert', @job_name = 'test_job'
 
--检索
exec sp_help_alert
 
 
/******************************************************************************************************************************************/
/*
 *SQL Server邮件
 *该存储过程在master数据库下执行
 */
--启动邮件服务
exec xp_startmail @user = 'jinxiangrong'
 
--发送邮件
exec xp_sendmail @recipients = '[email protected]', @message = 'The pubs database is full!'
 
--停止邮件服务
exec xp_stopmail
 

你可能感兴趣的:(Ms Sql Server 基本管理脚本(3))