Export the “functionality” of many stored procedur

2019-09-08 23:09发布

问题:

I have a large number of stored procedures (200+) that all collect clinical data and insert the result into a common table. Each stored procedure accepts the same single parameter, ClientID, and then compiles a list of diagnostic results and inserts them into a master table.

I have each clinical test separated into individual stored procedures however as I described in a previous SO question, the execution of the batch of these stored procedures pegs the CPU at 100% and continues on for hours before eventually failing. This leads me to want to create a single script that contains all the functionality of the stored procedures. Why you ask? Well, because it works. I would prefer to keep the logic in the stored procedure but until I can figure out why the stored procedures are so slow, and failing, I need to proceed with the "script" method.

So, what I am looking to do is to take all the stored procedures and find a way to "script" their functionality out to a single SQL script. I can use the "Tasks => Generate Scripts" wizard but the result contains all the Create Procedure and Begin and End functionality that I don't need.

回答1:

In the versions of studio, etc. I use, there are options to control whether to script out the "if exists statements".

If you just want to capture the procs without the create statements, you could be able to roll your own pretty easily usig sp_helptext proc

For example, I created this proc

create proc dummy (
@var1 int
, @var2 varchar(10)
) as
begin
return 0
end

When I ran sp_helptext dummy I get pretty much the exact same thing as the output. Comments would also be included

I don't know of any tool that is going to return the "contents" without the create, as the formal parameters are part of the create or alter statement. Which probably leaves you using perl, python, whatever to copy out the create statement -- you lose the parameters -- though I suppose you could change those into comments.