简体   繁体   中英

SSMS: How to view a stored procedure/view/function without scripting?

i want to look at the definition of a stored procedure, view, or user-defined function.

In SQL Server Management Studio 2005 the only way i've found to do this is:

  1. Right-click
  2. Script stored procedure as
  3. ALTER To
  4. New Query Editor Window
  5. goto 1

i don't want to script it, i want to look at it.

My task today in SSMS is to quickly go through the stored procedures to find one i'm interested in. i've loaded up Enterprise Manager in Windows XP mode (MMC snap-in doesn't run nativly in 64-bit), and my job is much easier:

  1. Push enter
  2. goto 1

i'm trying to find the way to look at a stored procedure - i'm not interested in scripting it.

I did some quick google searches and found this .

Copy and Paste from website:

-- Get Stored Procedure Content 
--    Name = Stored Procedure Name. 
--    Colid = Multiple lines, their sequence. 
SELECT text 
FROM syscomments 
WHERE id = (SELECT id FROM sysobjects WHERE name = '{0}') 
ORDER BY colid 

Depending on where the information is, have you tried to filter them "to find one I'm interested in"?

筛选存储过程

SELECT text
FROM syscomments c
INNER JOIN sysobjects o
ON o.id = c.id
WHERE o.type = 'P'
and o.Name = '{0}'
FOR XML PATH('')
exec sp_helptext N'<stored proc name>'

Example:

exec sp_helptext N'mydatabase.dbo.myStoredProc'

This will shows all the lines of the procedure without having to maneuver the GUI to the sp.

I found a solution for preview the stored function in SQL Server Management Studio 2012. It is non-programmer solution :)

  1. Find chosen function in Object Explorer.
  2. Click on it right mouse button.
  3. Choose Modify.
  4. Function preview is displayed. You can copy it to NotePad ++ and analyse.

I hope this will be helpful.

Using syscomments has potential problem: big procedures are splitted in several rows and sometimes important identifiers are divided into 2 parts. Like:

row1: .....veryimportantide

row2: ntifier.....

so, if you are looking for veryimportantidentifier - you will never find it. (for example - looking for all references of it)

When I look for something and it is very important - I generate scripts of all objects and navigate there using something like Notepad++ or Visual Studio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM