How do I query schema bound views?
I can list all views in SQL Server 2008 by using
SELECT * FROM sys.views
What I want to do is to 开发者_Python百科list only the views that are schema bound. How can I do this?
SELECT *
FROM sys.views
WHERE OBJECTPROPERTY(object_id, 'IsSchemaBound') = 1
I needed to find the schema bound views for a specific table. This worked for me in SQL Server 2019.
select distinct
o.type, SCHEMA_NAME(o.schema_id), o.name
--, *
from sys.sql_dependencies d
inner join sys.objects o
on d.object_id = o.object_id
where d.class = 1 -- OBJECT_OR_COLUMN_REFERENCE_SCHEMA_BOUND
and d.referenced_major_id = OBJECT_ID(N'dbo.MyTable')
order by 1, 2, 3
;
精彩评论