HeatherD
HeatherD

Reputation: 67

Enable System-Versioning on an Existing Table in Database

I'm trying to enable system versioning on an existing table in my database. The code I've written, however, is not working. I'm using SQL Server 2016.

The errors I'm getting are

Incorrect syntax near GENERATED (Line 4)

The other error is

Incorrect syntax near 'SYSTEM_VERSIONING' (Line 9)

Could someone please help me with what I'm doing wrong?

USE Evergreen;
GO

ALTER TABLE dbo.tblApplication 
    ADD [TimeStart] DATETIME2 
            GENERATED ALWAYS AS ROW START NOT NULL 
            CONSTRAINT DFT_tblApplication_TimeStart DEFAULT GETDATE(),
        [TimeEnd] DATETIME2 
            GENERATED ALWAYS AS ROW END NOT NULL 
            CONSTRAINT DFT_tblApplication_TimeEnd DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999'),
        PERIOD FOR SYSTEM_TIME ([TimeStart], [TimeEnd]);

ALTER TABLE dbo.tblApplication
    DROP CONSTRAINT DFT_tblApplication_TimeStart, DFT_tblApplication_TimeEnd;

ALTER TABLE dbo.tblApplication 
    SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.tblApplication_History));

Upvotes: 0

Views: 3477

Answers (1)

HeatherD
HeatherD

Reputation: 67

Nevermind, I have SQL Server 2014. That's why it's not working.

Upvotes: 1

Related Questions