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!
Try to avoid using the general "sys.objects" - use the more specific views instead - `sys.views`
marc_s
2010-05-25 10:33:26
+1
A:
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
hgulyan
2010-05-25 09:11:02
+2
A:
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.
AdaTheDev
2010-05-25 09:38:20