This is quick but interesting trick to display the text of Stored Procedure in the result window. Open SQL Query Analyzer >> Tools >> Customize >> Custom Tab
type sp_helptext against Ctrl+3 (or shortcut key of your choice)
Press CTRL + T to enable the text view in result window.
Type any Stored Procedure name in your database, select the SP name and type Ctrl+4.
You will see the Stored Procedure text in the Result Window.
As SQL Server 2005 and onwards version of SQL Server now uses Management Studio instead of query analyzer.
Here are additional blog posts related to the this blog:
- SQL SERVER – SP to display code (text) of SP, Trigger, View or Object
- SQL SERVER – Simple Use of Cursor to Print All SP of Database
- SQL SERVER – sp_HelpText for sp_HelpText – Puzzle
- Fastest Way to Display Code of Any SP – Interview Question of the Week #094
Let us see the fastest way to display code of the SP.
First, go to SQL Server Management Studio and select option Results to Text (shortcut CTRL+T).
Next type following script in Query Editor and hit execute. Do not forget to replace the string ‘NameofYourSP’ with the name of your actual stored procedure.
Reference: Pinal Dave (http://www.SQLAuthority.com)
For Microsoft SQL Server Management Studio 14.0.17119.0, follow below steps to set shortcut key:
Step 1: Tools >>Options>> Environment>>Keyboard and then click on the expansion arrow to list the options under
Step 2: Click on the ‘Query Shortcuts’ option and you will see a list of some shortcut.
Step 3: Type ‘sp_helptext’ under Stored Procedure column next to your preferred shortcut key and press Ok button.
Step 4: Close and Open the Microsoft SQL Server Management Studio editor and check.
Hope this will help.