所以我不能在临时表的列定义中有 NOT NULL?

So I can't have NOT NULL in column definition of temporal tables?

我正在使用 SQL Server 2016 并尝试创建 Temporal table。这是定义:

USE zbachoreTest
GO`enter code here`
IF EXISTS (SELECT 1 FROM sys.tables WHERE name = 'People' AND temporal_type_desc ='SYSTEM_VERSIONED_TEMPORAL_TABLE' )
ALTER TABLE dbo.People SET( SYSTEM_VERSIONING = OFF)
DROP TABLE IF EXISTS dbo.People 
CREATE TABLE dbo.People(
    PersonID INT IDENTITY(1,1) NOT NULL CONSTRAINT PK_People PRIMARY KEY(PersonID),
    FirstName VARCHAR(50) NOT  NULL,
    LastName VARCHAR(50)  NULL,
    StartTime DATETIME2 GENERATED ALWAYS AS ROW START NOT NULL
        CONSTRAINT DF_People_StartTime DEFAULT SYSDATETIME(),
    EndTime DATETIME2 GENERATED ALWAYS AS ROW END NOT NULL
        CONSTRAINT DF_People_EndTime DEFAULT CONVERT(DATETIME2,'9999-12-31 23:59:59.9999999'),
    PERIOD FOR SYSTEM_TIME(StartTime,EndTime)
    ) WITH (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.PeopleHistory))

当我 运行 上面的代码时,我收到以下错误消息: 消息 13531,级别 16,状态 1,第 7 行 将 SYSTEM_VERSIONING 设置为 ON 失败,因为列 'FirstName' 在 tables 'zbachoreTest.dbo.People' 和 'zbachoreTest.dbo.PeopleHistory'.

中没有相同的可空性属性

请各位大侠帮忙。谢谢!

是的,你可以。

先做drop table dbo.PeopleHistory。如果它已经存在,则只会对其进行验证,而不会重新创建。

发件人:https://docs.microsoft.com/en-us/sql/relational-databases/tables/creating-a-system-versioned-temporal-table

The history table must always be schema-aligned with the current or temporal table, in terms of number of columns, column names, ordering and data types.

If the table specified by the HISTORY_TABLE parameter already exists, it will be validated against the newly created temporal table in terms of schema consistency and temporal data consistency. If you specify an invalid history table, the CREATE TABLE statement will fail.