Reputation: 8856
I want to create a trigger in foxpro that will execute after every update in my db table, for example JobActivity.After every update, the trigger should insert the update time in the table JobActivity.
Upvotes: 1
Views: 3217
Reputation: 574
After every update, the trigger should insert the update time in the table JobActivity.
My first assumption is that this data table updating is done in a VFP application.
If so, then great. You only need to look where this updating is being done and add the necessary code to also update your jobActivity table with the date/time.
And if the table being updated is itself, the jobActivity table, then the UPDATE or REPLACE command used to update the other data only needs to be modified to also write this Update Tracking field - simple. In fact if you wanted to do so, you could easily also add the Initials, etc. of the individual doing the update.
If you are doing this in an application using a different language you can still add code to issue a SQL UPDATE to the jobActivity table.
Good Luck
Upvotes: 0
Reputation: 48179
Instead of AFTER the update, you could apply a Record RULE validation (as @Stuart Dunkeld mentions) that is applied against the entire record before the insert/update is processed.
Go to your database container and create a stored procedure something like
FUNCTION SP_LastUpdated()
replace LastEditDT WITH DATETIME()
RETURN .t.
ENDFUNC
Then, for the record validation rule, put in SP_LastUpdated().
Upvotes: 2
Reputation: 73303
You would want to use the Create Trigger command then, except you have one problem: a VFP trigger cannot update the table which fires it (as otherwise it would end out in an endless loop)
I had a solution for this in a project I did many years ago, I think it used the Record Validation rule to do the update, I will look it up when I get home and post it.
Upvotes: 0