Sql Query to list all views in an SQL Server 2005

2019-03-17 03:00发布

I need an sql query to enumerate all views (I only need the view names) of a specific database in SQL Server 2005. Thanks in advance!

6条回答
在下西门庆
2楼-- · 2019-03-17 03:27
SELECT  *
FROM    sys.objects
WHERE   type = 'V'
查看更多
手持菜刀,她持情操
3楼-- · 2019-03-17 03:28

Some time you need to access with schema name,as an example you are using AdventureWorks Database you need to access with schemas.

 SELECT s.name +'.'+v.name FROM sys.views v inner join sys.schemas s on s.schema_id = v.schema_id 
查看更多
forever°为你锁心
4楼-- · 2019-03-17 03:30

To finish the set off (with what has already been suggested):

SELECT * FROM sys.views

This gives extra properties on each view, not available from sys.objects (which contains properties common to all types of object) or INFORMATION_SCHEMA.VIEWS. Though INFORMATION_SCHEMA approach does provide the view definition out-of-the-box.

查看更多
我命由我不由天
5楼-- · 2019-03-17 03:30
SELECT SCHEMA_NAME(schema_id) AS schema_name
,name AS view_name
,OBJECTPROPERTYEX(OBJECT_ID,'IsIndexed') AS IsIndexed
,OBJECTPROPERTYEX(OBJECT_ID,'IsIndexable') AS IsIndexable
FROM sys.views
查看更多
Rolldiameter
6楼-- · 2019-03-17 03:31

Run this adding DatabaseName in where condition.

  SELECT TABLE_NAME, ROW_NUMBER() OVER(ORDER BY TABLE_NAME) AS 'RowNumber' 
  FROM INFORMATION_SCHEMA.VIEWS 
  WHERE TABLE_CATALOG = 'DatabaseName'

or remove where condition adding use.

  use DataBaseName

  SELECT TABLE_NAME, ROW_NUMBER() OVER(ORDER BY TABLE_NAME) AS 'RowNumber' 
  FROM INFORMATION_SCHEMA.VIEWS 
查看更多
\"骚年 ilove
7楼-- · 2019-03-17 03:36
select v.name
from INFORMATION_SCHEMA.VIEWS iv
join sys.views v on v.name = iv.Table_Name
where iv.Table_Catalog = 'Your database name'
查看更多
登录 后发表回答