Import Existing Stored Procedures In SQL Server

你。 提交于 2019-12-03 16:00:55

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.

Austin Salonen

For SQL 2K & 2K5, you want this tool.

I asked a similar question awhile ago and got this advice from Mike L (give him votes here).

pramod rai
  1. Right click on the database from where you want to transfer the data
  2. Select Data Transfer
  3. Select Tables or Store Procedure (what you want to transfer)
  4. Select the location where you want to transfer the data (either on server or localhost or any file)
Martijn Laarman

Right click on the development database Hit Generate SQL Scripts and then only select stored precedures. If you need need additional filtering you can even select the stored procedures you dont want.

Then just run that query on development.

I don't know if there's a command line way to do it, but if you have them all in text files, it shouldn't be difficult at all to write a quick down and dirty app that just loops through all the files, and runs the create statements on your production server using whatever language you choose.

If like me you have to deal with a bunch of sql files in a hierarchy of folders, this one liner will combine them into a single file called out.sql which you can easily execute in SQL Management studio. It will only include files that END in .sql, and ignore files such as *.sqlsettings.

Run it from the root folder of the hierarchy of .sql files. Be sure you have nothing of value in out.sql, as it will be replaced.

del out.sql && for /f %f in ('dir /b /s ^| findstr /E \.sql') do type %f >> out.sql
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!