Search code examples
mysqlsqldatedefault-valuecreate-table

Default Date Value in MySQL create table not working


I have the following create table statement (in MySQL):

CREATE TABLE bugs (id INT, open_date DATE, 
close_date DATE DEFAULT STR_TO_DATE('9999-99-99', '%Y-%m-%d'), severity INT); 

Unfortunately, it is not working and returns an error because of the default date value. Any other way to set a particular default value to date when using the create table statement? Thanks in advance.


Solution

  • Try this

    CREATE TABLE bugs (id INT, open_date DATE, 
    close_date DATE DEFAULT '9999-99-99', severity INT); 
    

    for more information, use the below link:-

    How do you set a default value for a MySQL Datetime column?