导入 SQL Server 中现有的存储过程

发布于 2024-07-10 18:00:37 字数 142 浏览 8 评论 0原文

我从生产中恢复了我的开发数据库,​​但我的开发环境中所需的存储过程在我的生产数据库中不存在。 是否有一个命令可以用来将开发的存储过程导入回 SQL Server。 大约有 88 个文件,因为每个过程都在不同的文本文件中。

蒂亚! 克里斯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

蘸点软妹酱 2024-07-17 18:00:37

哎呀,您以痛苦的方式生成了脚本。 您应该通过右键单击 SSMS 中的数据库,选择任务 -> 为所有过程创建一个脚本。 生成脚本。

但是,如果您不想再次经历该过程,请在文件夹中打开一个 cmd shell 并记住那些旧的批处理文件时代:

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

这应该可以解决问题!
如果需要,您可以向 sqlcmd 添加其他参数(即登录名、密码、服务器名称等)。 要查看开关列表,只需执行sqlcmd -h

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.

缱倦旧时光 2024-07-17 18:00:37

对于 SQL 2K 和 2K5,您需要此工具

我不久前问过类似的问题,并从 Mike L 那里得到了这个建议(给他投票 这里)。

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).

强者自强 2024-07-17 18:00:37
  1. 右键单击要传输数据的数据库
  2. 选择数据传输
  3. 选择存储过程(要传输的内容)
  4. 选择您想要传输数据的位置(在服务器或本地主机或任​​何文件上)
  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)
踏月而来 2024-07-17 18:00:37

右键单击开发数据库,​​点击“生成 SQL 脚本”,然后仅选择存储的过程。 如果您需要额外的过滤,您甚至可以选择您不需要的存储过程。

然后只需在开发中运行该查询即可。

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.

万劫不复 2024-07-17 18:00:37

我不知道是否有命令行方法可以做到这一点,但是如果您将它们全部放在文本文件中,那么编写一个快速且肮脏的应用程序(仅循环遍历所有文件)应该不难,并且使用您选择的任何语言在生产服务器上运行创建语句。

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.

赠意 2024-07-17 18:00:37

如果像我一样,您必须处理文件夹层次结构中的一堆 sql 文件,这个衬垫会将它们组合成一个名为 out.sql 的单个文件,您可以在 SQL Management studio 中轻松执行该文件。 它只会包含以 .sql 结尾的文件,并忽略 *.sqlsettings 等文件。

从 .sql 文件层次结构的根文件夹运行它。 确保 out.sql 中没有任何有价值的内容,因为它将被替换。

del out.sql && for /f %f in ('dir /b /s ^| findstr /E \.sql') do type %f >> out.sql

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文