I know I can get views metadata using sys.views
system catalog view. But now I want to create a centralized function in my master
database to be called from other databases.
For example, I want to create a procedure, to refresh all views inside a database:
select 'execute sp_refreshview ''' + object_name([object_id], db_id()) + ''''
from sys.views
I know that I can pass db_id
to the object_name
for example, to retrieve data from another database. But how can I tell SQL Server that it should use the sys.views
of another database?