title: Possible BUG with BACPAC import and temporal tables
body: <p>I' using the latest version of SQL Server 2016 Developer edition and SSMS (13.0.15600.2).</p>
  
  <p>There is a possible bug in importing Data tier Application (<code>bacpac</code>) that contain any temporal tables and any object (function. view) that references them with 'WITH SCHEMABINDING'.</p>
  
  <p>It is perfectly possible to export such database to backpac but when importing it back - there is an error: </p>
  
  <blockquote>
    <p>Error SQL72014: .Net SqlClient Data Provider: Msg 3729, Level 16, State 4, Line 1 Cannot ALTER 'Table2Version' because it is being referenced by object 'BindTest'.
     Error SQL72045: Script execution error.  The executed script:
     ALTER TABLE [dbo].[Table2Version] SET (SYSTEM_VERSIONING = OFF);</p>
  </blockquote>
  
  <p>The smallest DB creation script that will reproduce this problem is:</p>
  
  <pre><code>USE [master]
   GO
  
  
  CREATE DATABASE [temptest]
   GO
  
  
  ALTER DATABASE [temptest] SET COMPATIBILITY_LEVEL = 130
   GO
  
  
  USE [temptest]
   GO
  
  
  CREATE SCHEMA [History]
   GO
  
  
  CREATE TABLE [History].[Table2Version](
    [Id] [int] NOT NULL,
    [Name] [nvarchar](50) NULL,
    [SysStartTime] [datetime2](0) NOT NULL,
    [SysEndTime] [datetime2](0) NOT NULL
   ) ON [PRIMARY]
  
  
  GO
  
  
  CREATE CLUSTERED INDEX [ix_Table2Version] ON [History].[Table2Version]
   ([SysEndTime] ASC, [SysStartTime] ASC )
   GO
  
  
  SET ANSI_NULLS ON
   GO
   SET QUOTED_IDENTIFIER ON
   GO
   CREATE TABLE [dbo].[Table2Version](
    [Id] [int] NOT NULL,
    [Name] [nvarchar](50) NULL,
    [SysStartTime] [datetime2](0) GENERATED ALWAYS AS ROW START HIDDEN NOT NULL,
    [SysEndTime] [datetime2](0) GENERATED ALWAYS AS ROW END HIDDEN NOT NULL,
    CONSTRAINT [PK__Table2Version] PRIMARY KEY NONCLUSTERED ( [Id] ASC ),
    PERIOD FOR SYSTEM_TIME ([SysStartTime], [SysEndTime])
   ) ON [PRIMARY]
   WITH ( SYSTEM_VERSIONING = ON (HISTORY_TABLE = [History].[Table2Version] , DATA_CONSISTENCY_CHECK = ON ))
  
  
  GO
  
  
  CREATE FUNCTION [dbo].[BindTest]()   
   RETURNS TABLE   
   WITH SCHEMABINDING    
   AS    
   RETURN SELECT Id AS id
   from dbo.Table2Version  ;  
  
  
  
  GO
  </code></pre>
  
  <p>Is it really a bug or I'm doing something wrong?</p>