December 6, 2011 at 11:23 pm
Dear All,
I need to create a log file in SQL Server 2008 which records the activities of the tables such as Insert, Update and Delete. The log file should record the transaction with time and system name.Please help in this regarding. Thanks in advance.
With Regards,
K.Anandhakumar
December 6, 2011 at 11:40 pm
anandha31 (12/6/2011)
Dear All,I need to create a log file in SQL Server 2008 which records the activities of the tables such as Insert, Update and Delete. The log file should record the transaction with time and system name.Please help in this regarding. Thanks in advance.
With Regards,
K.Anandhakumar
Please explain your requirement so that we can help you better. You want to do this for each & every table in the database or is it for some tables ?
You can add triggers on those tables, which you want to be audited. Using triggers you can store the required data in some audit table you want.
December 6, 2011 at 11:43 pm
OR BTW, I forgot to ask, do you really want to create a log file i.e. (.ldf file) because your database has got corrupt OR you have only the data file (.mdf file) so you want to recover this database ?
December 6, 2011 at 11:53 pm
Divine Flame (12/6/2011)
OR BTW, I forgot to ask, do you really want to create a log file i.e. (.ldf file) because your database has got corrupt OR you have only the data file (.mdf file) so you want to recover this database ?
@Sujit: I don't think so he is talking about database log file. I assume its application log file that tracks changes to database operations.
@Anandha: Please confirm if my assumption is correct. Also if it's the case then you need to provide more information on requirements because we can log it in database tables easily. It would be handy for further analysis as well e.g. number of Inserts in a day, Failed Attempt of Inserts in a day etc.
December 6, 2011 at 11:54 pm
try to look for Change Data Capture(cdc) feature of Sql Server. This would be efficient than creating triggers for each table especially when you have lots of table to be monitored/audited.
"Often speak with code not with word,
A simple solution for a simple question"
December 6, 2011 at 11:59 pm
Dear Sujeet,
Thanks for your reply. Actually I want to know when data are inserting / updating / deleting into the table and by whom it is happening? This should be for every table in the database. If anyone insert the data or delete the data in the table then I want to know who did that and from which system it has been made?. I am not able to identify. So I thought to trace the activites. But I dont know how to do? Because I am new to this.
December 7, 2011 at 12:00 am
Yes Ofcourse you are correct Mr.Dev
December 7, 2011 at 12:10 am
anandha31 (12/6/2011)
Actually I want to know when data are inserting / updating / deleting into the table and by whom it is happening? This should be for every table in the database. If anyone insert the data or delete the data in the table then I want to know who did that and from which system it has been made?. I am not able to identify. So I thought to trace the activites. But I dont know how to do? Because I am new to this.
Considering your audit / logging requirements, I would suggest you to hire a professional. As you said you are new to this, it would be difficult for you.
There are many options available and all of them have merits & demerits. A professional can assess your requirements & can suggest you better. PM me if you need more information.
Here is something for you to start with...
What, When and who? Auditing 101
December 7, 2011 at 12:10 am
anandha31 (12/6/2011)
Dear Sujeet,Thanks for your reply. Actually I want to know when data are inserting / updating / deleting into the table and by whom it is happening? This should be for every table in the database. If anyone insert the data or delete the data in the table then I want to know who did that and from which system it has been made?. I am not able to identify. So I thought to trace the activites. But I dont know how to do? Because I am new to this.
Hi Anandha.....As mhike2hale said go and for Change Data Capture(cdc) feature of Sql Server
2008 this is new feature,To know more follow the link
Hope this helps....
Need help? Help us help you.
December 7, 2011 at 12:22 am
Thanks Mr.Dev. I got an idea. Let me try CDC. If I find any difficulties then I will come back.
Also Thanks to all those who gave suggesstion
December 7, 2011 at 12:24 am
Thanks Mr.Tommey. I got an idea. Thanks to all those who gave suggesstions.
December 7, 2011 at 12:24 am
anandha31 (12/6/2011)
Dear Sujeet,Thanks for your reply. Actually I want to know when data are inserting / updating / deleting into the table and by whom it is happening? This should be for every table in the database. If anyone insert the data or delete the data in the table then I want to know who did that and from which system it has been made?. I am not able to identify. So I thought to trace the activites. But I dont know how to do? Because I am new to this.
As Mhike suggested above you can go for CDC if you are using SQL Server 2008. Tommy has provided a good link above for you to understand it better.
I am not sure if CDC provides the user name also who changed the data. In that case, you can use triggers on the tables.
However, applying the triggers on all the tables may reduce the performance, so test, test, & test before applying :cool:.
December 7, 2011 at 12:53 am
anandha31 (12/6/2011)
This should be for every table in the database.
Note that, if you try to store all the insert/delete/update info for all the tables in the db, it can grow larger if it is a long term requirement.
anandha31 (12/6/2011)
Dear Sujeet,Thanks for your reply. Actually I want to know when data are inserting / updating / deleting into the table and by whom it is happening? This should be for every table in the database. If anyone insert the data or delete the data in the table then I want to know who did that and from which system it has been made?. I am not able to identify. So I thought to trace the activites. But I dont know how to do? Because I am new to this.
I have few suggestion here.
1) Add columns called UserName and CreateDate to all the tables. Set SUSER_SNAME() and GETDATE() as DEFAULT vaulue. This will automatically give you information about who inserted the row and when.
2) Write stored procedure for insert/delete/update. Don't allow insert/delete/updates directly to the table. In the stored procedure you can capture additional information for auditing.
3) SQL Server 2008 has new Auditing features.
December 7, 2011 at 1:53 am
Dear Suresh,
Thanks for your suggestion.I cant add new column for that. Because tables are related with .net application. Let me try with CDCI.
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply