March 10, 2013 at 5:33 pm
Hello --
We have SQL Server 2008R2 standard running on one of our servers. The server contains three databases. One of the databases contains data that normally does not change, and is of such nature that if a change occurs, the administrators should be notified of the event. The databases on the server all part of a maintenance plan that includes Full, Differential, and Transaction Log backups, the last of which is backed up once every hour. The Database Mail utility has been configured so that notifications of job failures are sent to the administrators.
A colleague of mine suggested that a trigger could be created that would monitor the transaction logs for entries that recorded any changes in the database. This trigger could then send a notification to the administrators. I had several questions concerning this approach.
1. Is this the correct approach?
2. If the answer to the first question is yes, is this something that can be done through the SQL Studio?
March 10, 2013 at 6:08 pm
Have you examined / evaluated the use of Change Data Tracking. If not you may want to start here"
http://msdn.microsoft.com/en-us/library/bb933875(v=sql.105).aspx
March 11, 2013 at 7:11 am
Hi!
I wrote a simple script one time that can help you on this question:
/*
TRACKING DML COMMANDS (INSERT,UPDATE,DELETE)
BY ANDRÉ CÉSAR RODRIGUES 13/09/2012 V1
*/
--FIRST YOU NEED TO CREATE IN SOME DATABASE THE TABLE BELOW THAT WILL KEEP THE TRACKING DATA
CREATE TABLE DMLMon(Changed TIMESTAMP,DateChanged DateTime,TableName char(30),UserName varchar(50),AppName varchar(50),host_name varchar(50),Operation char(6))
--DROP TABLE DMLMon
--CHANGE THE NAME TbMon FOR THE NAME OF THE TABLE YOU WANT TO MONITORING.
CREATE TRIGGER AuditDML ON TbMon
AFTER
INSERT, UPDATE, DELETE
AS DECLARE @Operation char(6)
if exists (select * from inserted) and exists (select * from deleted)
select @Operation = 'Udate'
else if exists (select * from inserted)
select @Operation = 'Insert'
else
select @Operation = 'Delete'
INSERT INTO DATABASE.dbo.DMLMon(DateChanged,TableName,UserName,AppName,host_name,Operation)
SELECT GetDate(), 'TbAuditada', suser_sname(),app_name(),host_name(),@Operation
-- Change the DATABASE to the name of the database that you create the table in the beggining of this script.
/*
Good luck!
Regards,
March 11, 2013 at 7:16 am
kaplan71 (3/10/2013)
A colleague of mine suggested that a trigger could be created that would monitor the transaction logs for entries that recorded any changes in the database. This trigger could then send a notification to the administrators. I had several questions concerning this approach.1. Is this the correct approach?
2. If the answer to the first question is yes, is this something that can be done through the SQL Studio?
Well, first problem there is that the transaction log is not a table and can't have a trigger put on it. Second problem is that the transaction log is not an audit log, it's for database integrity and durability.
Have a look at Change Data Capture and SQLAudit
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply