Add a generated column using alter table statement

454 views Asked by At

I'm not able to add a generated column using an alter table statement in SQL Server 2017. I'm trying to create a temporal table from an existing table as discussed in the following link: https://learn.microsoft.com/en-us/sql/relational-databases/tables/creating-a-system-versioned-temporal-table?view=sql-server-ver15

But alter table shows an error:

Incorrect syntax near generated

GO 

ALTER TABLE InsurancePolicy 
ADD SysStartTime DATETIME2 GENERATED ALWAYS AS ROW START HIDDEN
 CONSTRAINT DF_SysStart DEFAULT SYSUTCDATETIME() , SysEndTime DATETIME2 GENERATED ALWAYS AS ROW END HIDDEN CONSTRAINT DF_SysEnd DEFAULT CONVERT(DATETIME2, '9999-12-31 23:59:59.9999999'), 
PERIOD FOR SYSTEM_TIME (SysStartTime, SysEndTime); 

GO 

ALTER TABLE InsurancePolicy SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = History.InsurancePolicy)); 
0

There are 0 answers