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

后端 未结 26 2076
野的像风
野的像风 2020-11-22 01:55

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

In SQL Server it\'s getdate(). What is the equivalant for MySQL? I\'m using MySQL 5.x if tha

相关标签:
26条回答
  • 2020-11-22 02:40

    While you can't do this with DATETIME in the default definition, you can simply incorporate a select statement in your insert statement like this:

    INSERT INTO Yourtable (Field1, YourDateField) VALUES('val1', (select now()))
    

    Note the lack of quotes around the table.

    For MySQL 5.5

    0 讨论(0)
  • 2020-11-22 02:44

    You can resolve the default timestamp. First consider which character set you are using for example if u taken utf8 this character set support all languages and if u taken laten1 this character set support only for English. Next setp if you are working under any project you should know client time zone and select you are client zone. This step are mandatory.

    0 讨论(0)
提交回复
热议问题