开发者

Mysql Trigger Or just a simple Insert statement .. which one is better to log history?

I have so many tables in my DB. eg. user, organisation,etc.

**User**

us开发者_开发问答erId,name,age,orgId,etc..

**SessionLog**
logId, userId, operations, reason

If one admin makes changes like inserting, updating ,deleting, I will log every operations in SessionLog table WHAT he made.

So I plan to use Trigger.But the problem is I want to log the userId for WHO too. By using Trigger WHAT is OK. But for logging WHO, how can I do ?

1) do I need to retrieve the logId and need to update the row with WHO?

or

2) just use the simple INSERT statement to log everything? which way is better?

3) Is there any way to pass desired parameters to Trigger?

Thanks.


1. User

You can use CURRENT_USER to get this. http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_current-user

2. Insert statement vs. Trigger

A trigger will abstract logging away from everybody else, and usually is the easiest solution that stays hidden.

INSERTS / UPDATES will not return until the trigger has completed.

Therefore while triggers on tables with light activity is an OK idea, it will become a real hindrance when dealing with tables that have a lot of activity.

Another option is to encapsulate this in the data access layer, but if you have even a single user that has direct access to the data (DBA included) then I do not recommend this approach.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜