mysql5.5中timestamp问题

时间:2022-05-08 04:58:29

 

 

use database_name;

--
--  namespace table
--

CREATE TABLE `table_name`
(
    `id`          int(11)      NOT NULL AUTO_INCREMENT,
    `name`        varchar(128) NOT NULL COMMENT 名字,
    `create_time` timestamp    NOT NULL COMMENT 创建时间,
    `update_time` timestamp    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 更新时间,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_name` (`name`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8 COMMENT =‘table_name
  AUTO_INCREMENT = 1;

 

######上面的建表语句不会成功执行,需要修改成下面这样的,原因是因为timestamp类型的字段与CURRENT_TIMESTAMP

use database_name;

--
--  namespace table
--

CREATE TABLE `table_name`
(
    `id`          int(11)      NOT NULL AUTO_INCREMENT,
    `name`        varchar(128) NOT NULL COMMENT 名字,
    `create_time` timestamp     NOT NULL DEFAULT 0000-00-00 00:00:00 COMMENT 创建时间,
    `update_time` timestamp    NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 更新时间,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_name` (`name`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8 COMMENT =table_name
  AUTO_INCREMENT = 1;