如何创建一个时间戳列默认为 DATETIME('now')
的表?
像这样:
CREATE TABLE test (
id INTEGER PRIMARY KEY AUTOINCREMENT,
t TIMESTAMP DEFAULT DATETIME('now')
);
这会出错。
最佳答案
截至version 3.1.0您可以将 CURRENT_TIMESTAMP
与 DEFAULT 一起使用子句:
If the default value of a column is CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP, then the value used in the new row is a text representation of the current UTC date and/or time. For CURRENT_TIME, the format of the value is "HH:MM:SS". For CURRENT_DATE, "YYYY-MM-DD". The format for CURRENT_TIMESTAMP is "YYYY-MM-DD HH:MM:SS".
CREATE TABLE test (
id INTEGER PRIMARY KEY AUTOINCREMENT,
t TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
关于sql - 如何创建默认值为 'now' 的时间戳列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/200309/