-1

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: enter image description here Query:

ALTER TABLE `students` ADD `date_submitted` TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP AFTER ;

The error I'm receiving:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Server version: 5.5.34 - MySQL Community Server (GPL)

KoKsMAN
  • 59
  • 1
  • 10
  • You could always try [THE ? Manual](http://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html) Its all in there somewhere – RiggsFolly Jun 29 '16 at 17:58

2 Answers2

1

Remove 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.

Jocelyn
  • 11,209
  • 10
  • 43
  • 60
0

Remove After Keyword at the end of your query

ALTER TABLEstudentsADDdate_submittedTIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;

Jahid Mahmud
  • 1,136
  • 1
  • 12
  • 32