Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a view table query (code) in SQL Server 2008 Management Studio

Tags:

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

like image 620
Sudhan Avatar asked Nov 25 '13 09:11

Sudhan


People also ask

How do I get the view code for SQL Server Management Studio?

Find your View > right click > "Design". This will give you the query you are looking for.

How can I see SQL code of query?

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.


1 Answers

In Management Studio, open the Object Explorer.

  • Go to your database
  • There's a subnode Views
  • Find your view
  • Choose Script view as > Create To > New query window

and you're done!

enter image description here

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'
like image 167
marc_s Avatar answered Sep 28 '22 10:09

marc_s