Executing stored procedures from the command prompt

Posted by Gsolvers under Sql Server on 3/16/2011 | Points: 10 | Views : 5501 | Status : [Member] | Replies : 3
Guys,
Below is command which you can use to execute stored procedures script on SQL server from command prompt. This will be definetely helpful if you have a folder where all scripts are stored and you want them to execute all. Normally you will execute all SPs 1 by 1 but with this command all the stored procedures scerpts will be executed without any hassle and this will save lot of time too!

for %f in (sprocs\*.sql) do sqlcmd -S <servername> -U <username> -P <password> -d <database> -i %f > > sprocs.txt


Above command will take all script from folder sprocs/* and will copy them in a text file. You can simply copy the content of text file in the SQL Analyzer window and execute them:)

Best Regards,

VG
www.TeacherJi.com



Responses

Posted by: T.saravanan on: 3/17/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Gsolvers,

Thanks for sharing this information.Its really helpful to anyone.
Continue your good job in our DNF............



Thanks,
T.Saravanan

Gsolvers, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rahuljgosavi on: 3/17/2011 [Member] Starter | Points: 25

Up
0
Down
Nice Pieace of information...Keep it up!!!

Regards,
Rahul

Gsolvers, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nilkanthn on: 3/17/2011 [Member] Starter | Points: 25

Up
0
Down
Very userful information....
Even i also needed it....

Thanks,
Nilkanth

Gsolvers, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response