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

后端 未结 26 2214
野的像风
野的像风 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:27

    Working fine with MySQL 8.x

    CREATE TABLE `users` (
          `id` int(11) NOT NULL AUTO_INCREMENT,
          `dateCreated` datetime DEFAULT CURRENT_TIMESTAMP,
          `dateUpdated` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
          PRIMARY KEY (`id`),
          UNIQUE KEY `mobile_UNIQUE` (`mobile`)
        ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
    

提交回复
热议问题