SQL Server/T-SQL Tutorial/System Tables Views/sys.views
Check a view against sys.views
IF EXISTS(SELECT *
FROM sys.views
WHERE name = "vS" AND schema_id =
SCHEMA_ID("HumanResources"))
DROP VIEW HumanResources.vS
GO
Query sys.views
4> SELECT top 10 name, schema_id
5> FROM sys.views
6> GO
name schema_id
-------------------------------------------------------------------------------------------------------------------------------- -----------
titleview 1
vwProductList 1
vV 1
(3 rows affected)
Reporting on Database Views by joining sys.columns and sys.views
4>
5>
6> SELECT v.name ViewName,
7> c.name ColumnName
8> FROM sys.columns c
9> INNER JOIN sys.views v ON
10> c.object_id = v.object_id
11> ORDER BY v.name,
12> c.name
13> GO
ViewName
ColumnName
------------------------------------------------------------------------------------------------------------------------
-------- ---------------------------------------------------------------------------------------------------------------
-----------------
(0 rows affected)
1>