I'm building registration form for my teacher's website.
I have created database called "students" with various rows like "name, surname etc."
Now I would like to add a column named "date_submitted" which will automatically insert current date and time to the row when data is submitted.
For example a student submits his data, the data is inserted into the table and mysql automatically fills the date and time when this insertion occured.
I tried @MLBDG answer from this question MySQL date column auto fill with current date but it doesn't work.
This is the way I do it:
ALTER TABLE `students` ADD `date_submitted` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER ;
AFTER keyword at the end of your query:
ALTER TABLE `students` ADD `date_submitted` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
Syntax: ALTER TABLE
If using the
AFTER keyword in your
ALTER TABLE query, it must be followed by the name of a field in the table you are modifying.