Home > Back-end >  How to find out the IsSchemaBound property of a view of another database
How to find out the IsSchemaBound property of a view of another database

Time:03-03

I need to find out whether a specific view is created by using SCHEMABINDING or not in another database. Currently I'm using OBJECTPROPERTY(SV.object_id, 'IsSchemaBound'). SV.object_id gets the correct object id of the view of another database. But the problem is, the built in function OBJECTPROPERTY() is only executable in current database context as per this ms doc.

Is there a way to execute OBJECTPROPERTY() function in another database context? Or is there any way to get the IsSchemaBound property of another database.

CodePudding user response:

You can use dynamic sql in the context of the target database, for example:

exec databasename.sys.sp_executesql N'select ObjectProperty(<objectId>, ''IsSchemaBound'')';

CodePudding user response:

You can just select straight out of the relevant database's system views

select v.*,
  m.is_schema_bound
from YourDB.sys.views v
join YourDB.sys.sql_modules m on m.object_id = v.object_id
where v.name = 'SomeView';
  • Related