使用 int、varchar 和 datetime2 数据类型创建表,但是在插入值后执行查询会导致错误

问题描述 投票:0回答:0

当我执行这个查询时(只是长代码的一部分):

CREATE TABLE web_events 
(
    id integer,
    account_id integer,
    occurred_at datetime2,
    channel varchar
);

INSERT INTO web_events VALUES (1, 1001, '2015-10-06 17:13:58', 'direct');
INSERT INTO web_events VALUES (2, 1001, '2015-11-05 03:08:26', 'direct');
INSERT INTO web_events VALUES (3, 1001, '2015-12-04 03:57:24', 'direct');
INSERT INTO web_events VALUES (4, 1001, '2016-01-02 00:55:03', 'direct');

我得到这个错误:

无法将显式值插入时间戳列。将 INSERT 与列列表一起使用以排除时间戳列,或将 DEFAULT 插入时间戳列。

除了

datetime2
之外,我还尝试过
occurred_at
列的不同数据类型,如
varbinary(8)
datetime
rowversion
。然而都导致了这个错误。

sql sql-server timestamp create-table datetime2
© www.soinside.com 2019 - 2024. All rights reserved.