title: The best mechanism for alter columns of system versioning tables (Temporal Table)?
body: <p>I have a system-versioning table with history table related as follows:</p>
  
  <pre><code>CREATE TABLE [dbo].[ExpenseCenter_Archive](
      [ExpenseCenterId] [tinyint] NOT NULL,
      [Name] [nvarchar](200) NOT NULL,
      [LineCode] [smallint] NOT NULL,
      [SysStartTime] [datetime2](2) NOT NULL,
      [SysEndTime] [datetime2](2) NOT NULL
  ) ON [FG_HISTORY]
  GO
  -------
  CREATE TABLE [dbo].[ExpenseCenter](
      [ExpenseCenterId] [tinyint] NOT NULL,
      [Name] [nvarchar](200) NOT NULL,
      [LineCode] [smallint] NOT NULL,
      [SysStartTime] [datetime2](2) GENERATED ALWAYS AS ROW START NOT NULL,
      [SysEndTime] [datetime2](2) GENERATED ALWAYS AS ROW END NOT NULL,
   CONSTRAINT [PK_ExpenseCenter] PRIMARY KEY CLUSTERED 
  (
      [ExpenseCenterId] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [FG_DATA],
  CONSTRAINT [UK_ExpenseCenterName] UNIQUE NONCLUSTERED 
  (
      [Name] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [FG_INDEX],
      PERIOD FOR SYSTEM_TIME ([SysStartTime], [SysEndTime])
  ) ON [FG_DATA]
  WITH
  (
  SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[ExpenseCenter_Archive] , DATA_CONSISTENCY_CHECK = ON )
  )
  GO
  </code></pre>
  
  <p>Now, I want alter data type of 'LineCode' in system-version table and history. After changes once again enabling it as follows:</p>
  
  <pre><code>--- Before edit column
  ALTER TABLE [dbo].[ExpenseCenter] SET (SYSTEM_VERSIONING = OFF);  
  -- ## Edit column in ssms ##
  
  --- After edit column
  ALTER TABLE [dbo].[ExpenseCenter] 
  SET    
  (   
  SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[ExpenseCenter_Archive])   
  );   
  </code></pre>
  
  <p>But I get the following error: </p>
  
  <p>Cannot set SYSTEM_VERSIONING to ON when SYSTEM_TIME period is not defined.</p>
  
  <p>How do I solve this issue.</p>