导入 SQL Server 中现有的存储过程
我从生产中恢复了我的开发数据库,但我的开发环境中所需的存储过程在我的生产数据库中不存在。 是否有一个命令可以用来将开发的存储过程导入回 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
哎呀,您以痛苦的方式生成了脚本。 您应该通过右键单击 SSMS 中的数据库,选择任务 -> 为所有过程创建一个脚本。 生成脚本。
但是,如果您不想再次经历该过程,请在文件夹中打开一个 cmd shell 并记住那些旧的批处理文件时代:
这应该可以解决问题!
如果需要,您可以向 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:
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
.对于 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).
右键单击开发数据库,点击“生成 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.
我不知道是否有命令行方法可以做到这一点,但是如果您将它们全部放在文本文件中,那么编写一个快速且肮脏的应用程序(仅循环遍历所有文件)应该不难,并且使用您选择的任何语言在生产服务器上运行创建语句。
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.
如果像我一样,您必须处理文件夹层次结构中的一堆 sql 文件,这个衬垫会将它们组合成一个名为 out.sql 的单个文件,您可以在 SQL Management studio 中轻松执行该文件。 它只会包含以 .sql 结尾的文件,并忽略 *.sqlsettings 等文件。
从 .sql 文件层次结构的根文件夹运行它。 确保 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.