I am looking for viewing the text of the system views and procedures in SQL Server 2005 using the object explorer or using sp_helptext.
actually i am coming from the SQL Server 2000 background, where we have the feature of retreiving the code of the view and the stored procedure using SQL Server 2000 Enterprise manager directly, but still i am unable to find this feature in the SQL Server 2005 Management Studio and still looking for the same feature for getting the view and procedure text in SQL Server 2005.
Kindly please help me in this.
This Stackoverflow posting has a database reverse engineering script that (amongst other things) reverse engineers view definitions. From the script
Note that
#views
is populated earlier in the script with a list of views to dump out. To select for a particular schema (also from the script)To get stored procedures, substitute 'P'; to get functions substitute 'FN' or 'TF'
In the
master
database the definitions for the system stored procedures live insys.system_views
, 'sys.system_objects, 'sys.system_columns
, andsys.system_sql_modules
. The queries in the reverse engineering script could be adapted fairly readily to get out the definitions of the system items by using these tables.Do you have access to SQL Server Management Studio? It is now sys.sp_helptext and can be browsed at master --> Programmability --> Stored Procedures --> System Stored Procedures in the object browser and executed with
All the information you are looking for can be found in the syscomments table which stores the definitions of all views, rules, defaults, triggers, CHECK constraints, DEFAULT constraints, and stored procedures. The SQL definition statements are stored in the "text" column.
Here's how to list all the Dynamic Management Views:
Unfortunately, if you run sp_helptext on these it doesn't give you much. For example,
Returns:
All the ones I tried gave the same result.
If you just want to see the text that defines a procedure:
Right click the stored procedure, and choose Modify. This will show the SQL that defines the stored procedure.
Or: right click, Script Stored Procedure as, CREATE To, New Query Editor Window.
The other answers are more advanced but I thought maybe you were asking a simple question :)