InsertOldUserIDHere
InsertOldUserIDHere

Reputation: 639

How to see the query that defines a view in SQL 2008

I am sure this is a simple question, but I am having no luck getting it answered.

I have a number of views in a MS SQL 2008 database I am now supporting but I am not able to find how to access the queries that define the views. I need to see that to get a list of all tables and databases the views are accessing.

Upvotes: 2

Views: 3101

Answers (2)

SQLMenace
SQLMenace

Reputation: 135181

several ways, right click on the view and select SCRIPT View AS-->CREATE TO--> New Query Window (see picture below) , don't click design because the designer doesn't support CASE and other statements

or

sp_helptext 'ViewName'

or

select object_definition(object_id('ViewName'))

or

select name, object_definition(object_id) 
from sys.views
where name = 'ViewName'

'

alt text

Upvotes: 5

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171589

Right-click on your view in the Object Explorer and select Design. If you do not see the SQL, then click the SQL button (likely 3rd button from the left) on the toolbar.

You can also right-click and select Script View as/Create To/New Query Editor Window.

Upvotes: 0

Related Questions