我使用最新版本的SQL Server 2016 Developer Edition和SSMS(13.0.15600.2)。
导入数据层应用程序(bacpac
)时可能存在错误,其中包含任何时态表和任何使用“WITH SCHEMABINDING”引用它们的对象(函数.view)。
将这样的数据库导出到backpac是完全可能的,但是当它导回时 - 有一个错误:
错误SQL72014:.Net SqlClient数据提供程序:消息3729,级别16,状态4,行1无法更改“Table2Version”,因为它正由对象“BindTest”引用。 错误SQL72045:脚本执行错误。执行的脚本: ALTER TABLE [dbo]。[Table2Version] SET(SYSTEM_VERSIONING = OFF);
将重现此问题的最小数据库创建脚本是:
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
这真的是一个错误,或者我做错了什么?