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 *
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'
right-click the view in the object-explorer, select "script view as...", then "create to" and then "new query editor window"
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
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.