Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 SQL AUDITING

Author  Topic 

garipi82
Starting Member

4 Posts

Posted - 2011-10-27 : 04:50:58
Hello everyone,

Is any possibilities to trace the SQL users which are making some queries for exc: Update, Insert, Delete. I mean that in case one user have don a query UPDATE to find which is the user, the row of the table which hi/she has don this update and the cell which is updated and what was there before updating and what is after updating.

Regards

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-27 : 04:58:19
you need to run sql profiler trace for that and filter based on user name

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-27 : 04:58:47
for getting before update and after update values use triggers

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

garipi82
Starting Member

4 Posts

Posted - 2011-10-27 : 05:26:56
Thank you, i tried triggers but i can not find what is modified and what was the original cell which is modified, can you give me an trigger exc for this. Please.

Regards
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-27 : 06:09:12
can you post your tried trigger? you should be using COLUMNS_UPDATE function to identify columns that took part in update and use INSERTED and DELETED tables to get value before and after update

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

garipi82
Starting Member

4 Posts

Posted - 2011-10-27 : 06:16:41
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [dbo].[pstdevHIS] ON [dbo].[PSTDEV]
FOR UPDATE
AS
if system_user<>'Banka'
begin
insert into pstdev_history select 'UPDATE',host_name(),system_user,getdate(),* from deleted
end

--select * from pstdev_history
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-27 : 07:15:08
you're not using COLUMNS_UPDATED() here. use it to get modified columns list

http://msdn.microsoft.com/en-us/library/ms186329.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

human12
Starting Member

5 Posts

Posted - 2011-10-27 : 07:21:56
I believe continuous running SQL profile will make lots of problems to your database,
Monitoring the actions through triggers, and creating sql login for each user who is going to update, to catch his username

I also believe this will be a headache for the server

you can check the new OUTPUT operator introduced in SQL 2005, it can help u big with tracking the changes through triggers as explained here

http://intosql.blogspot.com/2011/10/sql-server-2005-output-operator.html?utm_source=BP_recent



Tarek Omar
Technical Manager and Database Administrator
http://intosql.blogspot.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-27 : 07:26:46
quote:
Originally posted by human12

I believe continuous running SQL profile will make lots of problems to your database,
Monitoring the actions through triggers, and creating sql login for each user who is going to update, to catch his username

I also believe this will be a headache for the server

you can check the new OUTPUT operator introduced in SQL 2005, it can help u big with tracking the changes through triggers as explained here

http://intosql.blogspot.com/2011/10/sql-server-2005-output-operator.html?utm_source=BP_recent



Tarek Omar
Technical Manager and Database Administrator
http://intosql.blogspot.com


thats fine. but how will ensure this will capture all the data modifications happening? unless you include code using OUTPUT everywhere you cant capture all modifications. for example, if somebody does an ad-hoc update unless (s)he includes code with OUTPUT it wont capture details. Trigger though has some overhead provides you with a centralised option to capture DML actions. Once created, you dont have to worry on how you will capture required details for each and every DML operation done

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

human12
Starting Member

5 Posts

Posted - 2011-10-27 : 08:56:19
quote:
Originally posted by visakh16

quote:
Originally posted by human12

I believe continuous running SQL profile will make lots of problems to your database,
Monitoring the actions through triggers, and creating sql login for each user who is going to update, to catch his username

I also believe this will be a headache for the server

you can check the new OUTPUT operator introduced in SQL 2005, it can help u big with tracking the changes through triggers as explained here

http://intosql.blogspot.com/2011/10/sql-server-2005-output-operator.html?utm_source=BP_recent



Tarek Omar
Technical Manager and Database Administrator
http://intosql.blogspot.com


thats fine. but how will ensure this will capture all the data modifications happening? unless you include code using OUTPUT everywhere you cant capture all modifications. for example, if somebody does an ad-hoc update unless (s)he includes code with OUTPUT it wont capture details. Trigger though has some overhead provides you with a centralised option to capture DML actions. Once created, you dont have to worry on how you will capture required details for each and every DML operation done

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Total Agree

Tarek Omar
Technical Manager and Database Administrator
http://intosql.blogspot.com
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-27 : 09:21:55
<soapbox>
ONLY Allow sproc access to the data

Create triggers to move then entire BEFORE Image of Data to a history table

Log all sproc calls to a sproc log table

Running a trace remotely will not eat up as many resources as running it on the server itself

MOO

</soapbox>

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -