Tip of the Day : How to Get a List of User Views Within a Database

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - April 25, 2024

How to Get a List of User Views Within a Database

There are different ways of listing user views within a database.  The first method is with the sp_tables system stored procedure:

EXECUTE sp_tables @Table_Type = '''VIEW''', 
@Table_Owner = 'dbo'

The sp_tables system stored procedure returns a list of objects that can be queried in the current environment.  The sp_tables system stored procedure returns user tables, views and system tables.  To return only view, the @Table_Type parameter needs to be passed a value of ‘VIEW’.  So as not to include system views, the @Table_Owner parameters needs to be passed a value of ‘dbo’ or whatever is the owner of the views.

Another way of getting a list of views is with the INFORMATION_SCHEMA.VIEWS system view.  The INFORMATION_SCHEMA.VIEWS system view returns one row for each view in the current database for which the current user has permission.

SELECT [TABLE_NAME]
FROM INFORMATION_SCHEMA.VIEWS

Alternatively, the INFORMATION_SCHEMA.TABLES system view can also be used to return user views.

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'VIEW'

The INFORMATION_SCHEMA.TABLES system view returns both view and user tables.  To return just user views, the TABLE_TYPE needs to be checked for a value of ‘VIEW’.

The third way of getting a list of user views is by querying the different system views, namely, the sys.views, sys.objects and dbo.sysobjects.

SELECT [Name] FROM [sys].[views]
SELECT [Name] FROM [sys].[objects] WHERE [type] = 'V'
SELECT [Name] FROM [dbo].[sysobjects] WHERE [xtype] = 'V'

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions