Import Existing Stored Procedures In SQL Server

Chris picture Chris · Dec 18, 2008 · Viewed 29.7k times · Source

I restored my development database from production, and the stored procedures I need in my development environment doesn't exist in my production database. Is there a command Ii can use to import the developmetn stored procedures back into SQL Server. There are about 88 files, as each procedure is in a different text file.

TIA! Chris

Answer

mmx picture mmx · Dec 18, 2008

Oops, you did the painful way of generating scripts. You should have created a single script for all procedures by right clicking on the database in SSMS, choosing Tasks -> Generate Scripts.

However, if you don't want to go through that process again, open up a cmd shell in the folder and remember those old batch file days:

for %f in (*.sql) do sqlcmd -i %f

This should do the trick! You could add other parameters to sqlcmd if required (i.e. login, password, server name, ...). To see a list of switches just do a sqlcmd -h.