
Here’s the result I get when using a GUI (Azure Data Studio):Īnd here’s what I get using my command line interface: +-+ Each row contains 255 characters of the T-SQL definition.Įxample: EXEC sp_helptext 'uspGetAlbumsByArtist' This stored procedure displays the definition across multiple rows. As well as being able to return the definition for (unencrypted) stored procedures, it can also return the definition of a user-defined rule, default, view, user-defined Transact-SQL function, trigger, computed column, CHECK constraint, or system object such as a system stored procedure. Example 2 – The sp_helptext System Stored ProcedureĪnother method of returning a stored procedure’s definition is to use the sp_helptext system stored procedure. Alternatively, you could use the sp_helptext method below. In such cases you’ll need to do some extra work if you want it displayed in a more readable format. If you use a GUI (such as SSMS or Azure Data Studio) to return the results in a grid, the definition will likely be returned in one long line in a single cell. WHERE ArtistId = used a command line interface (CLI) with this example, so the result is nicely formatted. WHERE object_id = object_id('uspGetAlbumsByArtist') As the name implies, this returns the definition of the object. One of the columns returned with this view is called definition. In other words, you can use this view to return information about objects of various types, including functions, views, and of course, stored procedures. The sys.sql_modules system catalog view returns a row for each object that is an SQL language-defined module in SQL Server. Three of the methods here are exactly the same as the ones used for returning the definition of a view (except here, they’re being used on stored procedures instead of views).Įxample 1 – The sys.sql_modules System Catalog View The definition is the actual T-SQL statement used to create the stored procedure. This article presents 4 ways of using T-SQL to get the definition of a stored procedure in SQL Server.
