Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I've created a UDF that accesses the [INFORMATION_SCHEMA].[TABLES] view:

CREATE FUNCTION [dbo].[CountTables]

(

    @name sysname

)

RETURNS INT

AS

BEGIN

    RETURN

    (

        SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @name

    );

END

Within Visual Studio, the schema and name for the view are both marked with a warning:

SQL71502: Function: [dbo].[CountTables] has an unresolved reference to object [INFORMATION_SCHEMA].[TABLES].

I can still publish the database project without any problems, and the UDF does seem to run correctly. IntelliSense populates the name of the view for me, so it doesn't seem to have a problem with it.

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.

How can I resolve this warning?

1 Answer

0 votes
by (40.7k points)

Follow these steps to add a database reference to master:

1. Right-click on References, under the project.

2. Choose add database reference...

3. Select the System database.

4. Now, ensure that the master is selected.

5. Enter OK.

Related questions

Browse Categories

...