I have a view in SQL Server 2008 and would like to view it in Management Studio.
Example:
--is the underlying query for the view Example_1
select *
from table_aView
View name: Example_1
How to get the query of the corresponding view table (query used to create the view)?
In Management Studio, open the Object Explorer.
Views
Script view as > Create To > New query window
and you're done!
If you want to retrieve the SQL statement that defines the view from T-SQL code, use this:
SELECT
m.definition
FROM sys.views v
INNER JOIN sys.sql_modules m ON m.object_id = v.object_id
WHERE name = 'Example_1'