Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Create sp in a batch file

Author  Topic 

allan8964
Posting Yak Master

249 Posts

Posted - 2012-10-08 : 10:30:56
Hi there,

I got 20 stored procedures to create. I have scripts ready. Is there any way to run them in a batch file by some commands? I mean not run them in query windows one by one manually. Thanks in advance.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-10-08 : 11:33:22
Since you have only 20 stored procs, I would run them manually, one at time, making sure that there are no error messages as you create each stored proc.

If you do want to run them all together, if the scripts are in one file, you can separate the creation script for each with a batch separator (GO) and then run them all at once.
create procedure dbo.Proc1
as
...
GO
create procedure dbo.Proc2
as
...
GO


If the scripts are in separate files, you can create a command file that calls the SQLCMD utility to execute each file. You can also do a similar thing using a powershell script and SQLCMD or Invoke-SqlCmd.

But, to reiterate what I initially said: I would take 20 minutes and run them one at a time because it is easier to catch any errors/warnings when you are creating the stored procedures rather than trying to debug later.
Go to Top of Page
   

- Advertisement -