SSDT:未解析的对象引用

SSDT: Unresolved reference to object

我有一个现有的 SQL Server 2014 数据库,我想将它添加到源代码管理(Visual Studio 2017 中的 SSDT)。

我有一个包含大量视图和存储过程的数据库项目。 MyDatabase 是当前数据库。

每个视图和存储过程都是这样写的:

create view MyView 
as
    select
        Id
    from MyDatabase..MyTable

".." 表示此处的默认架构名称 (dbo)。它适用于 SQL 服务器。但是 SSDT 认为这样的构造是错误的:

View MyView has an unresolved reference to MyDatabase.dbo.MyTable.

所以 SSDT 非常清楚,数据库是 MyDatabase,跳过的模式名称是 dbo

但是我无法构建带有此类错误的项目。我也不能将 MyDatabase..MyTable 重写为 MyDatabase.dbo.MyTable.

那么SSDT这个问题有没有办法解决呢?

三部分名称可以替换为 [$(DatabaseName)]..MyTable:

select Id from MyDatabase..MyTable
=>
select Id from [$(DatabaseName)]..MyTable

Using local 3-part names in programmability objects

While VSTS:DB does not support local 3 part names it does support the use of variables and literals to resolve references to external databases. The $(DatabaseName) variable is an ambient variable that will have its value replaced at the time of deployment. This variable gets its value from the project properties deployment tab. Since $(DatabaseName) is always replaced at deployment with the target database name and references through variables are resolved you may use a variable in your local 3-part names.

Our guidance is to not use local 3-part names as it introduces an unnecessary layer of abstraction and dependency on the database name