是:如何使用查询备份选定的存储过程
我想通过命令行备份 200 个存储过程中的 10 个(在 SQL Server Management Studio 中)。有简单的方法吗?
现在,我正在使用“数据库”->“任务”->“生成脚本”选项,该选项引导我完成一系列对话框,在其中选择要导出的 SP。我想让这个过程变得简单,这样我就不必再重复一遍。
注意:我所说的导出是指将其打印在屏幕上,以便我可以复制它并将其保存在文本文件中。
Was: How to back up selected stored procedure using query
I would like to backup 10 out of 200 stores procedures over command line ( In SQL Server Management Studio). Is there an easy way to do it?
Right now I am using the Database->Tasks->Generate Scripts option, that takes me through a series of dialog where I choose the SP that I want to export. I would like to make this process easy, so I don't have to do it all over again.
Note: By Export I mean just print it on the screen so I can copy it and save it in a text file.
发布评论
评论(8)
使用 INFORMATION_SCHEMA.Routines 怎么样?
编辑
听起来您可能希望这样的内容在结果集中包含 LAST_ALTERED 日期和定义。
How about using INFORMATION_SCHEMA.Routines ?
EDIT
It sounds like you might want something like this to include the LAST_ALTERED date and Definition in a result set.
您可以使用以下查询选择所需的 SP:
另请参阅:http://www.sqlservercurry.com/2009/03/list-all-stored-procedures-of-database.html 和 http://www.sqlservercurry.com/2007/12 /redirect-select-query-output-to-text.html
You can select the SP's that you want with the following query:
See also: http://www.sqlservercurry.com/2009/03/list-all-stored-procedures-of-database.html and http://www.sqlservercurry.com/2007/12/redirect-select-query-output-to-text.html
以下 SQL 应该可以完成您想要的操作。
如果将上述 SQL 保存为名为 BackUpSprocs.SQL 的文件,则可以运行类似于以下内容的命令将输出获取到文件。
The following SQL should do what you want.
If you save the above SQL as a file named BackUpSprocs.SQL then you can run a command similar to the following to get your output to a file.
单击结果窗格中的链接可查看整个脚本。
Click on the link in the result pane to see the entire script.
看看这个。这可能对你有帮助。
Check this out. This may help you.
不是 SQL 方式,但我认为您可以使用 自动化数据库->任务->生成脚本选项/...更多步骤 .com/site/" rel="nofollow">autoit 或 Sikuli 或者其他一些 GUI 测试工具。
我在网络上尝试了一些 Sikuli,但它对我来说并不是 100% 可靠。
Not an SQL way, but I think you could automate your Database->Tasks->Generate Scripts option/...More Steps by using autoit or Sikuli or maybe some other GUI testing tool.
I tried a little of Sikuli for a web, and it was not 100% reliable for me.
我编辑了 MyItchyChin 的脚本,因为我发现其中存在一些缺陷。当 @part < 时,它将无限循环。 0 并且无法正确打印关闭过程代码的“END”关键字(“create procedure ... as begin...END”)。我还做了其他一些小的改变。我的问题现在已经解决了!非常感谢 MyItchyChin 提供的初始脚本。
Obs:我在 SQL Server 2008 R2 中使用这个脚本。该脚本还可用于编写函数脚本。
I edited MyItchyChin's script since I've found some flaws in it. It would loop indefinetely when @part < 0 and would not correctly print the "END" keyword that closes the procedure code ("create procedure ... as begin...END"). I did other minor changes too. My problems are now solved! Many thanks to MyItchyChin for the initial script.
Obs: I use this script in SQL Server 2008 R2. The script can also be used to script functions.
我创建了以下过程,该过程遍历所有 SP 和视图,特别是 DB(可以扩展到函数,...),并将每个代码脚本一一存储到 TXT 文件中。在 MS SQL 2008 R2 和 2014 上进行测试
第一部分将 SP 和视图的所有脚本插入临时表。然后稍后使用 BCP 实用程序。如果您愿意,可以使用导出 SSIS 包,而不是像我在本示例中所做的那样使用 SP。
循环遍历临时表,创建带有前缀 P_ 或 V_ 且后缀为日期的文件名,格式为 YYYYMMDD:
I have create following Procedure which goes thru all SP and Views in particular DB (can be extend to Functions, ...) and store each code script one by one into TXT files. Tested ON MS SQL 2008 R2 and 2014
First part Inserting all scripts of SP and Views into Temp table. Then later using BCP utility. If you wish you can can use for export SSIS package and not SP as I did in this example.
Loop goes thru temp table creating file name with Prefix P_ or V_ and with suffix as Date in format YYYYMMDD: