|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 97,
Visits: 465
|
|
Hi,
I need to detect when a new database is created in my SQL Server and send a mail notification to all dba-s.
My idea is to do that with notification services: first i capture the create database event, second i enquee message in the queue and finally i process this queue sending notification mails to all dba-s.
Someone could tell me if it is possible? How I can read the messages from a queue to send notifications by mail? How i can see the queue content?
Many thanks in advance.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, February 11, 2013 8:37 AM
Points: 1,382,
Visits: 641
|
|
depending on your version of sql2008 there is a audit function available to do that
there is also a trigger that will do that too
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Today @ 8:01 AM
Points: 73,
Visits: 303
|
|
Here is a Trigger that I created and currently use on SQL 2005 and 2008. It monitors when someone creates a new DB and emails me the information, including the create statement and the user. Note: it will not work on earlier versions of SQL.
CREATE TRIGGER [DDL_CREATE_DATABASE_EVENT] ON ALL SERVER FOR CREATE_DATABASE AS DECLARE @bd varchar(max) Declare @tsql varchar(max) Set @tsql = EVENTDATA().value ('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','varchar(max)') SET @bd = 'UserName: ' + UPPER(SUSER_NAME()) + '
ServerName: ' + @@SERVERNAME + '
Time: ' + CONVERT(varchar(25),Getdate()) + '
HostName: ' + HOST_NAME() + '
Database: ' + db_name() + '
T-SQL: ' + @tsql
BEGIN PRINT 'Make sure you have informed all DBAs before creating databases. This event has been logged'
EXEC msdb.dbo.sp_send_dbmail @profile_name = 'SQL Database Mail', @recipients = 'myEmail@myDomain.com', @subject = 'A new database has been created!', @body_format = 'HTML', @importance = 'High', @body = @bd END
GO
ENABLE TRIGGER [DDL_CREATE_DATABASE_EVENT] ON ALL SERVER GO
QUIGROUP- Need a Certified experienced DBA for a project or troubleshooting? Need help with programming, database recovery, performance tuning, ETL, SSRS or developing new databases? Contact us.. 1-786-273-9809
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Today @ 1:15 AM
Points: 97,
Visits: 465
|
|
| Many thanks to all for your help.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, April 29, 2013 11:43 AM
Points: 1,151,
Visits: 531
|
|
| Is it possible to do something like this for linked servers?
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 2:05 PM
Points: 2,013,
Visits: 1,566
|
|
Just a thought!
Will it not be good to create a new thread?
~Dev~
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 10:00 AM
Points: 1,605,
Visits: 2,783
|
|
If some user restore database from a copy of backup and give a new name, this is also considered as a new database, then the stored procedure won't notify that.
how can we deal this situation?
Thanks
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 1:35 AM
Points: 95,
Visits: 1,083
|
|
|
|
|