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
This question is related to
sql
sql-server
view
if i understood you can do the following
Right Click on View Name in SQL Server Management Studio -> Script View As ->CREATE To ->New Query Window
right-click the view in the object-explorer, select "script view as...", then "create to" and then "new query editor window"
Use sp_helptext
before the view_name
. Example:
sp_helptext Example_1
Hence you will get the query:
CREATE VIEW dbo.Example_1
AS
SELECT a, b, c
FROM dbo.table_name JOIN blah blah blah
WHERE blah blah blah
sp_helptext will give stored procedures.
Additionally, if you have restricted access to the database (IE: Can't use "Script Function as > CREATE To"), there is another option to get this query.
Find your View > right click > "Design".
This will give you the query you are looking for.
Source: Stackoverflow.com