问题描述
我之前已经看过这个问题,但是没有得到回答,所以就这样:
I have seen this question before but it is not answered, so here it goes:
创建表时,我有一列类型为Date的列.我希望默认值是系统日期(Sysdate),但是由于某种原因它不起作用,并且给出了一个错误(在语法上,这很奇怪,因为我遵循的是Mysql语法).
When creating a table, I have a column with the type Date. I want that the default value is the system date, (Sysdate), but for some reason it does not work and it gives an error (in syntax, which is strange because I am following the Mysql syntax).
create table students(
id integer(10),
name varchar (21) NOT NULL,
surname varchar(30),
grade integer check(grade in(1,2,3),
enrollment date default sysdate,
primary key(id) );
并且仅在"sysdate"处提供了语法错误.我尝试使用sys_date,sys-date和它是相同的.
And it gives an error in syntax just at the "sysdate". I have tried with sys_date, sys-date, and it is the same.
推荐答案
而不是sysdate
,请尝试使用CURRENT_TIMESTAMP
,例如:
Instead of sysdate
, try CURRENT_TIMESTAMP
like:
CREATE TABLE foo (
creation_time DATETIME DEFAULT CURRENT_TIMESTAMP,
modification_time DATETIME ON UPDATE CURRENT_TIMESTAMP
)
这篇关于在MySQL中键入日期默认sysdate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!