Monday, March 26, 2007

Output clause and Auditing of data

There is very common scenario to auditing of data in a table using triggers. In this case, the trigger uses information from the inserted and updated tables to add rows into the audit tables. MS has introduced a new OUTPUT clause in SQL Server 2005 to audit data instead of using triggers to insert rows into an audit table.

CREATE TABLE test (col INT NOT NULL);
CREATE TABLE test_audit ( old_col INT NOT NULL, new_col INT NULL);
INSERT INTO test (col) values( 1 );
INSERT INTO test (col) values( 2 );

UPDATE test
SET col = col + 1
OUTPUT deleted.col ,inserted.col into test_audit
WHERE col = 1;

DELETE FROM test
OUTPUT deleted.col, NULL into test_audit
WHERE col = 2;

SELECT * FROM test
SELECT * FROM test_audit;

2 comments:

Anonymous said...

A good Warhammer warhammer goldquest guide is a great resource whyvipwarhammergoldto have for finding your warhammer newsway around in the massive warhammer anlec-destructionworld of Warhammer Online. Warhammer Elite, created warhammer 40kby Steve Ferris, who calls himself warhammer supporta "no life gamer", is a perfect fit for warhammer belakor-orderthat role. Steve has been playing MMORPGs for many years and has been warhammer online offersinvolved with Warhammer Online since closed beta. He really wow goldknows his stuff and shares it all with you in his guide.Warhammer Elite clearly lays out a path to get you to level 40 without wasting a lot of time, and without missing half the content. The in-game screenshots and fully annotated maps, along with the detailed instructions and tips for completing quests, are designed to help guide you through the game as fast as possible. He even gives you pointers on how to engage the various mobs you will http://www.vipwarhammergold.com/encounter in your questing adventures.world of warcraft gold

aiya said...
This comment has been removed by a blog administrator.