表:
CREATE TABLE logaction
(
actype varchar(8) not null,
actime DATETIME not null,
devid int not null
);
Run Code Online (Sandbox Code Playgroud)
SQL:
insert into logaction values ('TEST', '2013-08-22', 1);
insert into logaction values ('TEST', '2013-08-22 09:45:30', 1);
insert into logaction values ('TEST', 'xyz', 2); // shouldn't this fail?
Run Code Online (Sandbox Code Playgroud)
无论actime列的非日期时间值如何,最后一条记录都会进入表中.为什么以及如何强制执行只有好的数据?
这是一个SQL小提琴.
嗯,Sqlite中没有DATETIME类型...
SQLite没有为存储日期和/或时间而预留的存储类.相反,SQLite的内置日期和时间函数能够将日期和时间存储为TEXT,REAL或INTEGER值:
Run Code Online (Sandbox Code Playgroud)TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS"). REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar. INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.应用程序可以选择以任何这些格式存储日期和时间,并使用内置的日期和时间函数在格式之间自由转换.
看文件
你可以像这样创建你的表,它不会改变任何东西.
CREATE TABLE logaction
(
actype varchar(8) not null,
actime NonexistingType not null,
devid int not null
);
Run Code Online (Sandbox Code Playgroud)