USE MASTER
GO
IF OBJECT_ID('dbo.sp_NotifyServerStart') IS NULL
EXEC('CREATE PROCEDURE dbo.sp_NotifyServerStart AS SELECT 1 AS ID')
GO
ALTER PROCEDURE dbo.sp_NotifyServerStart
AS
DECLARE @recipients NVARCHAR(1000) = 'ascheepers@corelogic.com;gvarol@corelogic.com;marsilva@corelogic.com',
@subject VARCHAR(1000) = 'SQL SERVER SERVICE STARTED'
SET NOCOUNT ON
IF @recipients <> ''
BEGIN
DECLARE @InFo NVARCHAR(MAX)
EXEC dbo.sp_SysInfo
@ReturnInfo = 1,
@InFo = @InFo OUTPUT
EXEC msdb.dbo.sp_send_dbmail
@recipients = @recipients,
@subject = @subject,
@body = @InFo
END
GO
EXEC sys.sp_ms_marksystemobject
sp_NotifyServerStart
GO
IF NOT EXISTS ( SELECT *
FROM sys.configurations
WHERE name = 'scan for startup procs'
AND value_in_use = 1 )
BEGIN
EXEC sp_configure
'show advanced option',
'1' ;
RECONFIGURE
EXEC sp_configure
'scan for startup procs',
'1' ;
RECONFIGURE
END
GO
IF ISNULL(OBJECTPROPERTY(OBJECT_ID('sp_NotifyServerStart'), 'ExecIsStartup'), 0) = 0
-- set it to run at sql server start-up
EXEC sp_procoption
N'sp_NotifyServerStart',
'startup',
'on'
GO