Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have you tried an Audit Trigger using the INSERTED and DELETED tables. <a href="http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx" rel="nofollow">http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx</a></p> <p>OR</p> <p>In your stored procedures for insert,delete,update you can make use FOR XML AUTO. To get the XML for the record and add it to an audit table. <a href="http://www.a2zdotnet.com/View.aspx?Id=71" rel="nofollow">http://www.a2zdotnet.com/View.aspx?Id=71</a></p> <p><em>UPDATE</em> A T-SQL example</p> <pre><code>BEGIN -- these tables would be in your database DECLARE @table TABLE(ID INT IDENTITY(1,1) PRIMARY KEY, STR VARCHAR(10), DT DATETIME) DECLARE @audit_table TABLE(AuditXML XML, Type VARCHAR(10), Time DATETIME) -- this is defined at the top of your stored procedure DECLARE @temp_table TABLE(PK INT) -- your stored procedure will add an OUTPUT to the temp table INSERT INTO @table OUTPUT inserted.ID INTO @temp_table VALUES ('test1', GetDate()), ('test2', GetDate() + 2) -- at the end of your stored procedure update your audit table INSERT INTO @audit_table VALUES( ( SELECT * FROM @table WHERE ID IN (SELECT PK FROM @temp_table) FOR XML AUTO ), 'INSERTION', GETDATE() ) -- your audit table will have the record data SELECT * FROM @audit_table END </code></pre> <p>In the example above you could make temp_table a clone of table (have all of the columns from table) and in your OUTPUT clause use INSERTED.* INTO @temp_table, this would avoid have to reselect the records before getting the FOR XML AUTO. Another note, for stored procedures that do DELETE you would use DELETED.* instead of INSERTED.* in your OUTPUT.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload