简体   繁体   English

SSMS:如何在不编写脚本的情况下查看存储过程/视图/功能?

[英]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: 在SQL Server Management Studio 2005中,我发现这样做的唯一方法是:

  1. Right-click 右键点击
  2. Script stored procedure as 脚本存储过程为
  3. ALTER To 更改为
  4. New Query Editor Window 新查询编辑器窗口
  5. goto 1 转到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: 我今天在SSMS中的任务是快速浏览存储过程,找到我感兴趣的存储过程。我已经在Windows XP模式下加载了Enterprise Manager(MMC管理单元无法在64位上正常运行),并且我的工作容易得多

  1. Push enter 按下Enter
  2. goto 1 转到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. 这将显示该过程的所有行,而无需将GUI操纵到sp。

I found a solution for preview the stored function in SQL Server Management Studio 2012. It is non-programmer solution :) 我在SQL Server Management Studio 2012中找到了预览存储功能的解决方案。这是非程序员解决方案:)

  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. 您可以将其复制到NotePad ++并进行分析。

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. 使用syscomments有一个潜在的问题:将大过程分成几行,有时将重要的标识符分为两部分。 Like: 喜欢:

row1: .....veryimportantide 第1行: ...非常重要

row2: ntifier..... 第2行: 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 当我寻找某些东西时,这非常重要-我生成所有对象的脚本并使用诸如Notepad ++或Visual Studio之类的东西导航到那里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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