sqlsql-serversql-server-2005schemabinding

Schema binding for a UDF using tables from other db


I have a UDF in SQL 2005 that I would need to schemabind as it is used in a view that I need an index on.

This UDF gets information from a table that is located in a different db (same server) then the one where the UDF is located.

Since it is invalid to specify table as [DBName].dbo.[Tablename], is there a way I can get the info from the table in the other db?


Solution

  • Schema binding is supposed to guarantee consistency. However consistency can not be guaranteed across two different databases, therefore schema-binding cannot be made across two different databases. In other words it's impossible to achieve.

    Imagine that, for example, one database is restored to an earlier point in time - the index on the indexed view would become corrupt and queries would be returning wrong results.