title: Updating temporal table history
body: <p>I'm having a problem updating rows in a temporal history table in MS SQL Server 2016.</p>
  
  <p>From the documentation, the steps that should be needed are as follows:</p>
  
  <ol>
  <li>Disable system versioning</li>
  <li>Modify the history table</li>
  <li>Enable system versioning again</li>
  </ol>
  
  <p>I tried creating a procedure that does this, but got this error: </p>
  
  <blockquote>
    <p>Msg 13561, Level 16, State 1, Line 23
    Cannot update rows in a temporal history table 'db.dbo.FooHistory'.</p>
  </blockquote>
  
  <p>Here is my SQL:</p>
  
  <pre><code>CREATE TABLE Foo(
      id int primary key not null
      , title nvarchar(50) not null
      , startTime datetime2 GENERATED ALWAYS AS ROW START NOT NULL
      , endTime datetime2 GENERATED ALWAYS AS ROW END NOT NULL
      , PERIOD FOR SYSTEM_TIME (startTime, endTime) )
  
  ALTER TABLE Foo
  SET (SYSTEM_VERSIONING = ON (HISTORY_TABLE = dbo.FooHistory));
  
  GO
  
  CREATE PROCEDURE [dbo].[UpdateFooHistory] AS
    BEGIN
      SET NOCOUNT ON
  
      SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
      BEGIN TRANSACTION;
      ALTER TABLE dbo.Foo SET (SYSTEM_VERSIONING = OFF);      
  
      UPDATE dbo.FooHistory
      SET title = 'Foo';
  
      ALTER TABLE dbo.Foo SET (SYSTEM_VERSIONING = ON (
        HISTORY_TABLE = dbo.FooHistory,
        DATA_CONSISTENCY_CHECK = ON
      ));
  
      COMMIT TRANSACTION
  
      RETURN 0
    END
  GO
  </code></pre>
  
  <p>It seems like SQL Server is checking if a table is temporal at "compile time" rather than at runtime. Is this true? Is there a way to work around it?</p>