a way to run sql to create stored procedures?

dkim18
dkim18 used Ask the Experts™
on
Hi
I have about 50 sqls which create stored procedures.
How can I create a batch file or something to run them all in one file?
Again these sqls are to create a stored procedures.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
You should be able to put all the commands into one SQL file and run at once to create them all.

Author

Commented:
I didn't want to open all those files and copy and paste.
Commented:
If you do that once, then you have them all together for the future.
Assuming all your script files are in the same folder you have several alternatives:

1) create a batch file, let's call it join.bat. like below: and run it from your command prompt. (Make sure you change the server and instance name below):

echo off
FOR %%X in ("*.sql") DO (
sqlcmd -S myServer\instanceName -i "%%X"
)

Open in new window


2) create the following script in your folder, and name it join.bat and then run it from the command prompt

echo off
FOR %%X in ("*.sql") DO (
type "%%X" >>result.s
echo/ >>result.s
echo GO >>result.s
echo/ >>result.s
)
ren result.s combined.sql

Open in new window


3) Use the COPY command

copy *.sql combined.sql

Last two will create a new file called "combined.sql" that you can execute from Management studio.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial