How to store the time of creation of record using a trigger/otherwise in Mysql
-
I want to automatically store request_time as the current time when keyword is updated. Here's a sample table: id request_time keyword 1 2011-02-03 8:00:08 free On inserting free, request_time should be set to NOW();. Here's the trigger i have but it doesnt work: delimiter // create trigger ai_update_userinput after update on user_input for each row begin update user_input set request_time = NOW(); end// Help appreciated.
-
Answer:
That should be possible with a timestamp column, even without a trigger. Take a look at http://dev.mysql.com/doc/refman/5.0/en/timestamp.html in particular the example for the 'on update' clause for the column spec in the table creation.
watkib at Stack Overflow Visit the source
Other answers
Timestamp columns already provide this functionality when they have DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP set. See http://dev.mysql.com/doc/refman/5.0/en/timestamp.html.
Lightness Races in Orbit
Related Q & A:
- How to store an image in database using MySQL?Best solution by stackoverflow.com
- How to store global date time and convert it to local date time?Best solution by Stack Overflow
- How to store more information using FormsAuthentication?Best solution by Quora
- Can you record your Xbox 360 using a digital camera?Best solution by support.xbox.com
- How do i scan something? First time using a scaner and i dont think im doing it right. help. thanks?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.