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 Programming
 changes to tables

Author  Topic 

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-03-11 : 14:03:31
is there a way of finding out if anything has been changed in a table

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-03-11 : 20:27:18
Changed since when? If you are talking about data, you have to find a way of doing it yourself, such as remembering a point in time or an ID then query the new value & compare it to the new. If you are talking about the definition of the table then yes (I can't remember how) but there is something wrong if you need to know that!
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2008-03-11 : 21:40:50
it would largely depend on "what", and what might be available as a checking source (like a backup or replicated data set?)



Poor planning on your part does not constitute an emergency on my part.

Go to Top of Page

pmccann1
Posting Yak Master

107 Posts

Posted - 2008-03-12 : 10:03:45
i want to know what data has been changed, is there a way of checking who changed it
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-03-12 : 10:09:09
not retorspectively. going forward you can look at triggers or profiler maybe

Em
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-12 : 12:50:06
quote:
Originally posted by pmccann1

i want to know what data has been changed, is there a way of checking who changed it


For tracking this, you can have audit columns on your table like datemodified,modifiedby,... and you can have a trigger to put the current date and current logged in persons name as values to them. this will enable them to track when & who did the modification last. If you want the entire history of modifications you can have a AUDIT table and populate this by means of the trigger. each time some actions take place.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-03-12 : 23:35:38
Or look at db log with third party tools.
Go to Top of Page

agelaus
Starting Member

3 Posts

Posted - 2008-03-13 : 01:09:16
For this we made a Trigger in our class. Ill type out the code we used.

USE <Your Database>
GO

--Create an Auditing Table
CREATE TABLE Audit<table Name> --table name is the table you want to
-- track changes on
(AuditTrailID INT IDENTITY,
AuditEvent NVARCHAR(6), --What was done
BeforeAfter NVARCHAR(6), --Befor or after change
AuditUsername NVARCHAR(30), --Who did the change
AuditDate DATETIME,
--Next you will list the columns of the table you are auditing
<columns of audited table>...
);
GO

CREATE TRIGGER <triggerName>
ON <audited Table> AFTER UPDATE
AS
INSERT INTO AuditAgents
SELECT 'Update', 'Before', USER_NAME(), GETDATE(),
<columns of the table>...
FROM deleted;

INSERT INTO AuditAgents
SELECT 'Update', 'After', USER_NAME(), GETDATE(),
<columns of the table>...
FROM inserted;
GO


You can then run a query on the Audit table to see what changes have been made.

Go to Top of Page
   

- Advertisement -