在SQL Server 2008设置发送邮件步骤详解

一、启用数据库邮件

手动启用数据库邮件功能,需执行以下脚本:

exec sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE ;
GO
exec sp_configure 'Database Mail XPs', 1;
GO
RECONFIGURE WITH OVERRIDE ;
GO

二、配置数据库邮件

配置过程如下图所示:

三、发送数据邮件示例

EXEC msdb.dbo.sp_send_dbmail 
   @profile_name = 'mail',  
   @recipients = '[email protected];[email protected]',  ----接收邮件地址列表,可以多个,中间以分号分隔
   @subject = '价格数据异常的记录',                     ----邮件主题
   @query='select  *   from test_sale
   where sale_price=0 and sale_date=convert(char(10),dateadd(dd,-1,getdate()),121)',     
   @body = '价格数据异常,查询结果如下:'  

四、可以根据实际业务需要,制定SQL作业计划,定时监控各数据表,出现异常数据时,及时邮件通知负责人。

猜你喜欢

转载自www.cnblogs.com/PeterFu/p/3981461.html