0
CREATE TABLE tests(
id INT PRIMARY KEY AUTO_INCREMENT,
day DATE DEFAULT CURDATE());

This code gives me error message: ERROR 1064 (42000): 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 'CURDATE()

I do not understand why. It works without DEFAULT CURDATE()

Can someone explains me why?

Thanks you very much!

johndoe
  • 4,387
  • 2
  • 25
  • 40
WQian
  • 13
  • 4
  • Please refer to this: https://stackoverflow.com/questions/39808684/mysql-date-field-with-default-curdate-not-datetime – Bernard Polman Sep 05 '18 at 05:55
  • 1
    Possible duplicate of [MySQL DATE field with default CURDATE(). NOT DATETIME](https://stackoverflow.com/questions/39808684/mysql-date-field-with-default-curdate-not-datetime) – David Makogon Sep 05 '18 at 05:57

1 Answers1

0

curdate() is date time function your assigning current date to a date variable

CREATE TABLE tests( id INT PRIMARY KEY AUTO_INCREMENT, `day` datetime DEFAULT now())

run this query

p.ganesh
  • 120
  • 4