天生舞男

我喜欢谦虚的学习各种...,希望自己能坚持一辈子,因为即使一张卫生巾也是有它的作用.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在SQL2005执行的命令和在命令行中等价的命令

Posted on 2005-12-07 13:32  天生舞男  阅读(791)  评论(0编辑  收藏  举报

PRINT ''
PRINT 'Installing default alerts...'
GO

IF (NOT EXISTS (SELECT *
                FROM msdb.dbo.sysalerts
                WHERE (name = N'Sample: Full msdb log')
                   OR ((severity = 0) AND
                       (message_id = 9002) AND
                       (database_name = N'msdb') AND
                       (event_description_keyword IS NULL) AND
                       (performance_condition IS NULL))))
 EXECUTE msdb.dbo.sp_add_alert
  @name = N'Sample: Full msdb log',
  @message_id = 9002,
  @severity = 0,
  @enabled = 1,
  @delay_between_responses = 10,
  @database_name = N'msdb',
  @notification_message = NULL,
  @job_name = NULL,
  @event_description_keyword = NULL,
  @include_event_description_in = 5; -- Email and NetSend
GO

IF (NOT EXISTS (SELECT *
                FROM msdb.dbo.sysalerts
                WHERE (name = N'Sample: Full tempdb')
                   OR ((severity = 0) AND
                       (message_id = 9002) AND
                       (database_name = N'tempdb') AND
                       (event_description_keyword IS NULL) AND
                       (performance_condition IS NULL))))
 EXECUTE msdb.dbo.sp_add_alert
  @name = N'Sample: Full tempdb',
  @message_id = 9002,
  @severity = 0,
  @enabled = 1,
  @delay_between_responses = 10,
  @database_name = N'tempdb',
  @notification_message = NULL,
  @job_name = NULL,
  @event_description_keyword = NULL,
  @include_event_description_in = 5; -- Email and NetSend
GO

IF (NOT EXISTS (SELECT *
                FROM msdb.dbo.sysalerts
                WHERE (name = N'Sample: Sev. 19 Errors')
                   OR ((severity = 19) AND
                       (message_id = 0) AND
                       (database_name IS NULL) AND
                       (event_description_keyword IS NULL) AND
                       (performance_condition IS NULL))))
 EXECUTE msdb.dbo.sp_add_alert
  @name = N'Sample: Sev. 19 Errors',
  @message_id = 0,
  @severity = 19,
  @enabled = 1,
  @delay_between_responses = 10,
  @database_name = NULL,
  @notification_message = NULL,
  @job_name = NULL,
  @event_description_keyword = NULL,
  @include_event_description_in = 5; -- Email and NetSend
GO

IF (NOT EXISTS (SELECT *
                FROM msdb.dbo.sysalerts
                WHERE (name = N'Sample: Sev. 20 Errors')
                   OR ((severity = 20) AND
                       (message_id = 0) AND
                       (database_name IS NULL) AND
                       (event_description_keyword IS NULL) AND
                       (performance_condition IS NULL))))
 EXECUTE msdb.dbo.sp_add_alert
  @name = N'Sample: Sev. 20 Errors',
  @message_id = 0,
  @severity = 20,
  @enabled = 1,
  @delay_between_responses = 10,
  @database_name = NULL,
  @notification_message = NULL,
  @job_name = NULL,
  @event_description_keyword = NULL,
  @include_event_description_in = 5; -- Email and NetSend
GO

IF (NOT EXISTS (SELECT *
                FROM msdb.dbo.sysalerts
                WHERE (name = N'Sample: Sev. 21 Errors')
                   OR ((severity = 21) AND
                       (message_id = 0) AND
                       (database_name IS NULL) AND
                       (event_description_keyword IS NULL) AND
                       (performance_condition IS NULL))))
 EXECUTE msdb.dbo.sp_add_alert
  @name = N'Sample: Sev. 21 Errors',
  @message_id = 0,
  @severity = 21,
  @enabled = 1,
  @delay_between_responses = 10,
  @database_name = NULL,
  @notification_message = NULL,
  @job_name = NULL,
  @event_description_keyword = NULL,
  @include_event_description_in = 5; -- Email and NetSend
GO

IF (NOT EXISTS (SELECT *
                FROM msdb.dbo.sysalerts
                WHERE (name = N'Sample: Sev. 22 Errors')
                   OR ((severity = 22) AND
                       (message_id = 0) AND
                       (database_name IS NULL) AND
                       (event_description_keyword IS NULL) AND
                       (performance_condition IS NULL))))
 EXECUTE msdb.dbo.sp_add_alert
  @name = N'Sample: Sev. 22 Errors',
  @message_id = 0,
  @severity = 22,
  @enabled = 1,
  @delay_between_responses = 10,
  @database_name = NULL,
  @notification_message = NULL,
  @job_name = NULL,
  @event_description_keyword = NULL,
  @include_event_description_in = 5; -- Email and NetSend
GO

IF (NOT EXISTS (SELECT *
                FROM msdb.dbo.sysalerts
                WHERE name = N'Sample: Sev. 23 Errors'
                   OR ((severity = 23) AND
                       (message_id = 0) AND
                       (database_name IS NULL) AND
                       (event_description_keyword IS NULL) AND
                       (performance_condition IS NULL))))
 EXECUTE msdb.dbo.sp_add_alert
  @name = N'Sample: Sev. 23 Errors',
  @message_id = 0,
  @severity = 23,
  @enabled = 1,
  @delay_between_responses = 10,
  @database_name = NULL,
  @notification_message = NULL,
  @job_name = NULL,
  @event_description_keyword = NULL,
  @include_event_description_in = 5; -- Email and NetSend
GO

Open Command Prompt windows.
Change current directory to C:\Program Files\Microsoft SQL Server\90\Samples\Engine\Administration\Alerts\Scripts.
Execute the following command to execute the script: sqlcmd -E -i agent_sample_alerts.sql