Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with audit table trigger
Message
 
 
To
27/02/2014 12:25:03
General information
Forum:
Microsoft SQL Server
Category:
Scripting
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01595410
Message ID:
01595470
Views:
32
>>>Naomi, Because you run only procedure for create tracking trigger. Simply, fast...
>>>
>>>Don Freeman, where you fill variable @TipID?
>>>
>>>MartinaJ
>>>
>>I agree with what Kevin wrote. There is no need to overcomplicate the trigger with dynamic SQL.
>
>All -
>
>Thanks for your feedback (I think). To expand a little further on this matter, as I said in the original post, I found this code on the internet. Actually, I found the code that generated this code, on the internet. I was looking for a way to create triggers for an audit table and it works well, although I confess it is mostly Greek to me. I can write fairly well in VFP (and have done this in VFP) but this is my first venture into SQL scripting and it is pretty confusing. Martina answered Naomi's original question. It was fast and easy. The script I found generated the audit table AND triggers for every table in the database. (There are about 40 of them.) So it was fast and easy to create, if not necessarily fast to run. BUT, while this is a large database, it has a fairly small number of users and not a ton of traffic. So transaction speed is not a particular concern.
>
>Martina asks where do I populate the value of @TipID. The answer is I guess I don't. That is probably my problem. While I look at the code I don't see how/where the other parameters are populated either. So if I knew how to do that I could probably solve it.
>
>Both Kevin and Naomi suggest there is a simpler and more straightforward way. I am sure there is, and if either of you have an example to share I would be glad to rewrite this thing along simpler lines. But at this point I can't see how to get the old and new values that need to be logged.
>
>Anyone have any more for me?
>
>Thanks

So, for every column in the table you insert a column into Audit table (in case that field was changed):

insert audit (Type, TipID, TableName, PrimaryKeyField, PrimaryKeyValue, FieldName, OldValue, NewValue, UpdateDate, UserName)

?

Do you want to always insert TipID column's value along with other values?

In this case I can change your dynamic SQL code because writing code for every column in a table will be a bit long as well.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform