SQL Server Database Project in Visual Studio is throwing an error on Temporal Table creation

rryofs0p  于 2023-04-28  发布在  SQL Server
关注(0)|答案(1)|浏览(142)

I have a SQL Server Database Project in Visual Studio 2022 and I want to create a temporal table with data retention for 12 months. When I wrote this in SSMS the script works but when I move it to Visual Studio project it errors out.

Could you please advise if there is something I'm missing here to make this work?

CREATE TABLE [dbo].[Franchises]
(
    [FranchiseID] INT NOT NULL PRIMARY KEY IDENTITY, 
    [Name] NVARCHAR(100) NOT NULL, 
    [ShortName] NVARCHAR(50) NOT NULL, 
    [ModifiedBy] NVARCHAR(250) NULL, 
    [ModifiedOn] DATETIME NULL DEFAULT GetDate(), 
    [CreatedBy] NVARCHAR(250) NULL, 
    [CreatedOn] DATETIME NULL DEFAULT GetDate(),     
    [StartDate] DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN NOT NULL, 
    [EndDate] DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN NOT NULL, 
    PERIOD FOR SYSTEM_TIME (StartDate, EndDate), 
)
WITH
(
    SYSTEM_VERSIONING = ON 
    (
        HISTORY_TABLE = dbo.FranchiseHistory,
        DATA_CONSISTENCY_CHECK = OFF,
        History_retention_period = 12 MONTHS
    )
)

https://i.stack.imgur.com/PbzhM.png

I ran the script in SSMS and it worked, the same script in Visual Studio Database project throws an exception. I have attached the image in my question.

bgibtngc

bgibtngc1#

It looked like the target platform needed to be changed. after I changed clean then rebuild fixed it. see image below

相关问题