Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Query to list all views in an SQL Server 2005 database

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!

like image 844
Mats Avatar asked May 25 '10 09:05

Mats


People also ask

How do you get a count of views in SQL Server?

Only possible way is to actually execute select COUNT(*) from view_name , because views can contain complicated logic and the data returned by them actually is allocated to other objects (e.g. tables). For tables for example, you can get this rows count from sys. partitions DMV.

Can you query a view in SQL?

A view is nothing more than a SQL statement that is stored in the database with an associated name. A view is actually a composition of a table in the form of a predefined SQL query. A view can contain all rows of a table or select rows from a table.


1 Answers

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.

like image 57
AdaTheDev Avatar answered Sep 23 '22 22:09

AdaTheDev