Trigger for populating created date field [message #52902] |
Tue, 20 August 2002 00:41 |
HKS
Messages: 1 Registered: August 2002
|
Junior Member |
|
|
Hi
As a standard, all our tables have created_date and modified_date. Is it worth having a trigger on every table to populate these fields, or should we just do it from the code?
Thanks
HKS
|
|
|
|
Re: Trigger for populating created date field [message #52909 is a reply to message #52902] |
Tue, 20 August 2002 05:13 |
Sanjay Bajracharya
Messages: 279 Registered: October 2001 Location: Florida
|
Senior Member |
|
|
If your business logic permits, default the 'created_date' to 'sysdate' and do not populate this field, which will then take the sysdate. As for modified_date, in your code, put the sysdate when that row is actually modified.
You can avoid the triggers this way, at least in this case.
Cheers.
|
|
|
Re: Trigger for populating created date field [message #52917 is a reply to message #52902] |
Tue, 20 August 2002 12:42 |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
The only reason for avoiding triggers is that it gives you more code to manage. You can easily create a trigger for each table to maintain those fields. If you need some other business logic on one of thhose tables (for insert or update) then create a second trigger to hold that. In that way you can create the triggers automatically (create the trigger scripts using sqlplus or pl/sql). The coders shouldn't have to worry about populating those fields and making the business logic more difficult to follow. The advantage of a trigger is that it always fires (as long as it's enabled) irrespective of how the data gets into the table. You can track IP addresses, usernames etc too.
|
|
|