<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx</link><description>How do you track changes to data in your database? There are a variety of supported auditing methods for SQL Server, including comprehensive C2 security auditing , but what do you do if you're solving a business rather than a security problem, and you</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7288604</link><pubDate>Tue, 22 Dec 2009 23:44:25 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7288604</guid><dc:creator>weliaccoula</dc:creator><author>weliaccoula</author><description>&lt;p&gt;Hi &lt;a rel="nofollow" target="_new" href="http://lenzaripa.gu"&gt;http://lenzaripa.gu&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7288604" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7283176</link><pubDate>Fri, 18 Dec 2009 12:15:27 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7283176</guid><dc:creator>Simbu</dc:creator><author>Simbu</author><description>&lt;p&gt;I have one query &lt;/p&gt;
&lt;p&gt;1. I have two databases namely (test, test_Audit)&lt;/p&gt;
&lt;p&gt;2. Both databases have same structure (schema), same tables, everything same. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;3.When I am going to insert new record in one table in test database that same data inserted into&lt;/p&gt;
&lt;p&gt; Test_ Audit database for the same table by using trigger. &lt;/p&gt;
&lt;p&gt;		Same for delete and update … &lt;/p&gt;
&lt;p&gt;Can u pls tell me the way …………….. &lt;/p&gt;
&lt;p&gt;I think it’s not possible to pass parameter into trigger... is it right &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7283176" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7280069</link><pubDate>Wed, 16 Dec 2009 11:56:45 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7280069</guid><dc:creator>Yassine Rabbouh</dc:creator><author>Yassine Rabbouh</author><description>&lt;p&gt;C'est tr&amp;#233;s interessant!&lt;/p&gt;
&lt;p&gt;Merci beaucoup et bonne continuation.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7280069" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7271407</link><pubDate>Sat, 05 Dec 2009 10:35:34 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7271407</guid><dc:creator>Urbacharl</dc:creator><author>Urbacharl</author><description>&lt;p&gt;Alohi. Mi zer novazo. &lt;a rel="nofollow" target="_new" href="http://jestormani.net"&gt;http://jestormani.net&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7271407" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7242804</link><pubDate>Thu, 29 Oct 2009 22:02:09 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7242804</guid><dc:creator>Jose</dc:creator><author>Jose</author><description>&lt;p&gt;Hi, &lt;/p&gt;
&lt;p&gt;This is a good starting point to get audit records, however I&amp;#180;m trying to get a good performance solution.&lt;/p&gt;
&lt;p&gt;I&amp;#180;ve used the Profiler to see the trigger in action and it take:&lt;/p&gt;
&lt;p&gt;Normal Insert without Audit: &amp;nbsp;~0-1 ms&lt;/p&gt;
&lt;p&gt;Insert with trigger Audit: &amp;nbsp; &amp;nbsp;~36 ms &lt;/p&gt;
&lt;p&gt;I have a large application with heavy load and this result is not acceptable.&lt;/p&gt;
&lt;p&gt;I&amp;#180;m to modify the script to moving thing that are executed in &amp;quot;trigger&amp;quot; time to the &amp;quot;installation time&amp;quot;, also I'm creating 3 triggers (for Insert, update and Delete), in this way a lot of operations are avoided&lt;/p&gt;
&lt;p&gt;I get a good optimization, now the Insert take ~2 ms.&lt;/p&gt;
&lt;p&gt;I'll include my finished script when finished.&lt;/p&gt;
&lt;p&gt; 36 &lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7242804" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7215783</link><pubDate>Thu, 24 Sep 2009 17:22:53 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7215783</guid><dc:creator>Dan</dc:creator><author>Dan</author><description>&lt;p&gt;Freddy...I am having issues with running your modified code. &amp;nbsp;I can not seem to figure out what variable to change. &amp;nbsp;My Table Is 'FMP_RET_DATA' and I only want to audit that.&lt;/p&gt;
&lt;p&gt;Can someone please point me in the right direction?&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7215783" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7190621</link><pubDate>Thu, 03 Sep 2009 15:05:17 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7190621</guid><dc:creator>Matt</dc:creator><author>Matt</author><description>&lt;p&gt;This script was great, how can I edit it to track tables with composite keys so the primary key value displays as key1:value1 key2:value2&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7190621" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7180437</link><pubDate>Mon, 24 Aug 2009 20:26:29 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7180437</guid><dc:creator>JoeS</dc:creator><author>JoeS</author><description>&lt;p&gt;If you want just one line in the audit table for the insert or delete action, instead of each field begin audited, you can replace this code. &lt;/p&gt;
&lt;p&gt;SELECT @field = 0, &lt;/p&gt;
&lt;p&gt; &amp;nbsp;@maxfield = MAX(ORDINAL_POSITION) &lt;/p&gt;
&lt;p&gt; &amp;nbsp;FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TableName&lt;/p&gt;
&lt;p&gt;with this&lt;/p&gt;
&lt;p&gt;IF @Type = 'I' or @Type = 'D'&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt;	SET @maxfield = 1&lt;/p&gt;
&lt;p&gt;	SET @field = 0&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
&lt;p&gt;ELSE&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt;SELECT @field = 0, &lt;/p&gt;
&lt;p&gt; &amp;nbsp;@maxfield = MAX(ORDINAL_POSITION) &lt;/p&gt;
&lt;p&gt; &amp;nbsp;FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TableName&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7180437" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7155469</link><pubDate>Mon, 27 Jul 2009 19:30:18 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7155469</guid><dc:creator>Sean</dc:creator><author>Sean</author><description>&lt;p&gt;I suppose you need to give the DB user insert rights on the Audit table? &amp;nbsp;Our user is a db_datareader only on that database. &amp;nbsp;I know about the Execute As clause, but, unfortunately, it's SQL 2000 and that's not available there.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7155469" width="1" height="1"&gt;</description></item><item><title>re: Adding simple trigger-based auditing to your SQL Server database</title><link>http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx#7134812</link><pubDate>Fri, 26 Jun 2009 10:55:16 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:7134812</guid><dc:creator>wicks</dc:creator><author>wicks</author><description>&lt;p&gt;i want to add one more field which i have stored for user login and want his name to keep track which user has last updated or deleted data from table .&lt;/p&gt;
&lt;p&gt;if u have idea give me.&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=7134812" width="1" height="1"&gt;</description></item></channel></rss>