对对象的未解析引用[ INFORATION_SCHEMA ] . [表]

我已经创建了一个访问 [INFORMATION_SCHEMA].[TABLES]视图的 UDF:

CREATE FUNCTION [dbo].[CountTables]
(
@name sysname
)
RETURNS INT
AS
BEGIN
RETURN
(
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @name
);
END

在 VisualStudio 中,视图的架构和名称都标记为警告:

SQL71502: Function: [ dbo ] . [ CountTables ]有一个未解析的对象引用[ INFORATION _ SCHEMA ] . [ TABLES ]。

我仍然可以毫无问题地发布数据库项目,而且 UDF 似乎运行正确。IntelliSense 为我填充了视图的名称,所以它似乎没有问题。

I also tried changing the implementation to use sys.objects instead of this view, but I was given the same warning for this view as well.

我如何解决这个警告?

73061 次浏览

master添加数据库引用:

  1. Under the project, right-click 参考文献.
  2. 选择 添加数据库引用..。
  3. 选择 System database
  4. Ensure 师父 is selected.
  5. Press OK.

请注意,VS 可能需要一段时间才能更新。

Sam 说的是最好的解决办法。
但是,如果您有一个场景需要从一台在特定位置没有引用的机器上部署 dacpac,那么您可能会遇到麻烦。 另一种方法是打开你的。项目文件,并确保下面的标记对于要运行的生成配置的值为 false

<TreatTSqlWarningsAsErrors>false</TreatTSqlWarningsAsErrors>

这样,您就不需要向项目添加引用。

In our project, we already have a reference to master, but we had this issue. Here was the error we got:

SQL71502: Procedure: [Schema].[StoredProc1] has an unresolved reference to object [Schema].[Table1].[Property1].

To resolve the reference error, on the table sql file, 右键单击属性并验证 BuildSettings 设置为 Build。

改变它建立固定它。

I'm using VS 2019, And even after adding the master db reference still got this issue. Resolved this by Changing the target platform of the DB project as shown in the image below. I had to remove and add back the master db again after this change. enter image description here