March 13, 2010

3 Different Ways to display VIEW definition using SQL Server 2008 Management Studio

Here are 3 different ways to display VIEW definitions:

Method 1: Use sp_helptext

USE Northwind
sp_helptext Invoices

Method 2: Use SQL Server 2008 Management Studio

Open SSMS 2008. Choose the database and expand the ‘Views’ node. Right click on it > Script View as > CREATE To > Choose different options as shown below:

View Definition SSMS 2008

Method 3: If you want to display the name and definitions of all view in a database, use this query:

VIEW_DEFINITION as ViewDefinition


View Definition

Alternatively, you can also do a join between sys.views and sys.sql_modules to obtain the same result

Did you like this post?
kick it on
subscribe via rss subscribe via e-mail
print this post follow me on twitter

About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal



9 Responses to "3 Different Ways to display VIEW definition using SQL Server 2008 Management Studio"
  1. Madhivanan said...
    March 15, 2010 at 8:00 AM

    Note that information_schema.views will show you only 4000 characters

    Other reliable methods are


    select object_definition(object_id) from sys.objects
    where type='v'


    select * from sys.[sql_modules]
    where definition like 'CREATE VIEW%'


  2. Suprotim Agarwal said...
    March 16, 2010 at 2:14 AM

    Thanks Madhivannan. As mentioned in my post, making a JOIN (using objectid) between sys.views and sys.sql_modules will get the View Name and View Definition

  3. Jeffrey Wank said...
    March 22, 2010 at 2:38 AM

    Thank you Madhivaan and Suprotim for sharing your solutions. This is very useful as I used to manually check views from management studio. Knowledge does wonders!

  4. Anonymous said...
    July 6, 2010 at 6:31 AM

    Thanks guys, very useful posts!!

  5. Anonymous said...
    September 29, 2010 at 10:56 PM

    Very useful post. Keep up the good work guys... :)

  6. Santanu....... said...
    March 23, 2011 at 12:10 PM
    This comment has been removed by the author.
  7. Santanu....... said...
    March 23, 2011 at 12:18 PM

    A very handy post....!!

  8. Anonymous said...
    December 18, 2012 at 11:22 AM

    Thank you, this helped a lot!

  9. mike said...
    January 29, 2013 at 4:49 AM

    Here is how i do it:



Copyright © 2009-2016 All Rights Reserved for by Suprotim Agarwal | Terms and Conditions