-----------------------------------------------------------

New Message on MumbaiUserGroup

-----------------------------------------------------------
From: Pankil
Message 1 in Discussion

Hi, I want to log an Audit for all records being inserted, update & deleted in 
another table of following format ...   Audit Table
-----------
Type Varchar(1)  --- This will store 'I', 'U' or 'D'
TableName Varchar(100) --Tablename
PK Varchar(400) --Stores primarykey name & value of that table
ColumnName Varchar(100) --Field
NewValue Varchar(200) --Value being inserted
OldValue Varchar(200) --Old value in case of Update/Delete   Say for example I 
am creating a trigger on Table Test having follwing structure   Test
----
PKTest  int   --
PKTest1 int  -- PKTest & PKTest1 being composite primary key
F1 Varchar(5)
F2 Varchar(10)   firing following queries in Test Table 1. insert into Test 
Values (1, 1, 'A', 'B')
2. insert into Test Values (1, 2, 'A1', 'B1')
3. Update Test Set F1 = 'C' Where PKTest = 1 and PKTest1 = 1   Now Requirement 
is following data needs to be logged in to Audit Table   Case 1. 
Type = 'I'
TableName = 'Test'
PK = 'PKTest=1|PKTest1=1'
ColumnName = F1
NewValue = 'A'
OldValue = Null   Case 2. 
Type = 'I'
TableName = 'Test'
PK = 'PKTest=1|PKTest1=2'
ColumnName = F1
NewValue = 'A1'
OldValue = Null   Case 3. 
Type = 'I'
TableName = 'Test'
PK = 'PKTest=1|PKTest1=1'
ColumnName = F1
NewValue = 'C'
OldValue = 'A'   I am able to achive this output but the trigger I used is 
using a loop through All columns and check if column is updated or not ... if 
yes then insert into audit log ... For current scenario there is no issues and 
works fine ... but issue arises when I want to write the trigger on a table 
having more than 60 columns this slow down the inserts and update.   Is there 
any better way to write this trigger instead of looping through the column list 
and check for each column?

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/mumbaiusergroup/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to