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)?
Thanks in advance
Find your View > right click > "Design". This will give you the query you are looking for.
To view the SQL code for an Access query, open the query in query design view. Then click the “View” drop-down button in the “Results” button group on the “Design” tab of the “Query Tools” contextual tab in the Ribbon. From the drop-down menu of choices that appears, select the “SQL View” command.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With