MySQL datetime(0) NULL DEFAULT NULL 报错

问题描述

在使用 mysql 建表时,datetime 类型使用以下声明时

datetime(0) NULL DEFAULT NULL

mysql 会提示语法错误,原因是 datetime 长度不能设置为 0 

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 '(0) NULL DEFAULT NULL,

解决办法

datetime(0) 改为 datetime 

补充说明

datetime 默认设置为 CURRENT_TIMESTAMP时,CURRENT_TIMESTAMP 的长度同样不能指定为 0

datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0)

正确语法

datetime NULL DEFAULT CURRENT_TIMESTAMP
发布了135 篇原创文章 · 获赞 39 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq262593421/article/details/104874712