嗨我写了一个存储过程来检索有关空间不足的服务器磁盘驱动器的信息。现在我只是试图编写另一个存储过程发送电子邮件通知来通知客户端服务器磁盘空间不足。以下是我有:SQL存储过程中的语法错误发送电子邮件?
--Creating alert notification
CREATE PROC dbo.sp_drivespacelow1_alerts
@from varchar(100),
@to varchar(200),
@subject varchar(100),
@threshold int -- number of MB under which to launch an alert
AS
SET NOCOUNT ON
DECLARE @list nvarchar(2000) = '';
WITH core AS (
SELECT DISTINCT
s.volume_mount_point [Drive],
CAST(s.available_bytes/1048576 as decimal(12,2)) [AvailableMBs]
FROM
sys.master_files f
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.[file_id]) s
)
SELECT @list = @list + ' ' + Drive + ', '
FROM core
WHERE AvailableMBs < @threshold
IF LEN(@list) > 3 BEGIN
DECLARE @msg varchar(500) = 'Low Disk Space Notification. The following drives are currently reporting less than '
+ CAST(@threshold as varchar(12)) + ' MB free: ' + @list
EXEC msdb.dbo.sp_send_dbmail @profile_name = 'xxxxx',
@recipients = @to,
@subject = @subject,
@body = @msg
END
RETURN 0
GO --Check done every 5 mins
--To Run:
EXEC master.dbo.sp_drivespace_alerts
@threshold = 5120 --5 GB
@from = '[email protected]'
@subject = 'Low diskspace alert -ServerName Here'
@to = '[email protected]'
下面是我用什么来检查磁盘空间:
--Returns informations on drives with less than 5 GBs of disk space
CREATE TABLE #drives (
drive char,
[free] int
)
INSERT INTO #drives
EXEC master..xp_fixeddrives
SELECT drive, [free]
FROM #drives
WHERE [free] < 5 * 102
drop table #drives --must get rid of temporary tables in order to run again
眼下存储过程检查磁盘空间是很好,但一到发送电子邮件通知不断给我回这个错误: 消息2714,级别16,状态3,过程sp_drivespacelow_alerts,行37 数据库中已有一个名为'sp_drivespacelow_alerts'的对象。 消息102,级别15,状态1,行6 附近有语法错误@from',“@主题”
如果我注释掉这些代码两位并运行此错误: 消息102,15级,状态1,行7 “@to”附近的语法不正确。
请帮助谢谢!
重新标记'SQL-server'为'mysql'是obvisously不是使用 –