How to access the code behind a Stored Procedure?

Asked

Viewed 6,518 times

3

How can I access the code behind a stored procedure?
I’m using Microsoft SQL Server Management Studio.

  • You want to see the code of your database that is already created in the bank?

3 answers

7


In SQL Server Management Studio, expand the database where Procedure was created. Click on Programmability, then click on Stored Procedures. Within this directory of Stored Procedures you will see all the procedures created for this your database. Right-click on the name of the database you want to see the code, then select Script Stored Procedure as -> Modify.

4

If you want the text in a result cell, you can use this query:

select
    [text]
from
    sys.syscomments comm
    inner join sys.procedures procs on procs.object_id = comm.id
where
    procs.[name] = 'foo'

Just swap foo by the name of his Procedure.

If you want the text for reading, you can open a new query, tighten CTRL+T (this puts the query results in SSMS in text mode) and execute:

exec sp_helptext 'foo'

Once again, take over foo by the name of his Procedure.

Or you can go on: Server -> Databases -> its basis -> Programmability -> Stored Procedures

...Right click on the Precedent and then click on Modify. So you can even change and save your trial.

2

Command can be used:

sp_heltptext 'nomeCompletoDaProcedure'

That makes the Procedure return as records in the preview part of table on DB.
If you do not want the return as records can be used Ctrl+T before the execution to return the value as text as mentioned by the user Renan in the comments of this reply.

  • Tighten CTRL+T before executing it comes as a text only ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.