Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Execute Stored procedure scripts in bulk

 
   Database Help (Home) -> General Discussions RSS
Next:  SQL 2005 Installation Splash Error Requires admin..  
Author Message
tirath

External


Since: Jan 12, 2009
Posts: 1



(Msg. 1) Posted: Mon Jan 12, 2009 8:32 pm
Post subject: Execute Stored procedure scripts in bulk
Archived from groups: comp>databases>ms-sqlserver (more info?)

Hi,
I have a folder containing about 150 stored procedures. Is there a way
- through batch or command file to execute all of them at
once..execute all files ending in .sql extension (inside a folder).

Its not possible to list each SP name in a command file or execute
each SP in management studio.

please suggest.

thanks

 >> Stay informed about: Execute Stored procedure scripts in bulk 
Back to top
Login to vote
Dan Guzman1

External


Since: Aug 22, 2004
Posts: 840



(Msg. 2) Posted: Tue Jan 13, 2009 7:15 am
Post subject: Re: Execute Stored procedure scripts in bulk [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> I have a folder containing about 150 stored procedures. Is there a way
> - through batch or command file to execute all of them at
> once..execute all files ending in .sql extension (inside a folder).

A lowly Windows FOR command can help you here. The FOR command example
below will run all "sql" in the current folder and redirect stdout and
stderr output to a log file for later review:

FOR %f IN (*.sql) DO SQLCMD -E -S MyServer -d MyDatabase -I -i "%f" 2>&1
>>"sqlcmd.log"

You can also encapsulate this in command file for reuse. The difference is
that you need to precede the variables with a two percent signs instead of
one and pass the target server and database as command-line arguments:

FOR %%f IN (*.sql) DO SQLCMD -E -S %1 -d %2 -I -i "%%f" 2>&1 >>"sqlcmd.log"

Save the command as RunScripts.cmd in the same folder as your scripts and
execute with:

RunScripts MyServer MyDatabase

See Windows help for more information on FOR and other useful commands.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"tirath" wrote in message

> Hi,
> I have a folder containing about 150 stored procedures. Is there a way
> - through batch or command file to execute all of them at
> once..execute all files ending in .sql extension (inside a folder).
>
> Its not possible to list each SP name in a command file or execute
> each SP in management studio.
>
> please suggest.
>
> thanks

 >> Stay informed about: Execute Stored procedure scripts in bulk 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to return a Pk value from one stored procedure to anot.. - Dear All, I have one stored procedure like sp_insertEmployee Employee Table Fileds Eno int pk, ename varchar(100), designation varchar In stored Procedure After inserting the ename and designation it has to return the Eno pk Id..

iif stored procedure - Hi all, I have a bunch of queries initially written for MS Access that contain iif function. Since I'm new in SQL Server and I don't like the idea of rewriting all queries using CASE statement, I hope someone has written iif T-SQL stored procedure. I...

Need help writing a stored procedure - How would I write a stored procedure to get * where duedate is less than and not equal to today's date. Is this right? select * from library where duedate < != getdate() Thanks

Date Compare in SQL Server Stored Procedure - Hi, i have "req_date" column of "datetime" type in Database table besides other columns. From my Web page, i am calling the Stored Procedure with variable parameter "Search_Date" of Varchar(60) type. the value, i am pa...

Cleaning unused stored procedure best practice? - I've recently inhereted an environment in which we have over 600 stored procedures. The documentation is either very poor or non-existant and am needing advice on how to determine if a stored procedure has been used. Does SQL Server have any sort of..
   Database Help (Home) -> General Discussions All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]