SQL Server 2012:如何将所有数据库存储过程编写成单

SQL Server 2012 : How to script all database stored procedures into separate .sql files?(SQL Server 2012:如何将所有数据库存储过程编写成单独的 .sql 文件?)
本文介绍了SQL Server 2012:如何将所有数据库存储过程编写成单独的 .sql 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有存储过程从 SQL Server 2012 编写为 .sql 文件(在不同的项目中)到 Visual Studio 2012.我怎么做?每个存储过程都需要一个 .sql 文件吗?在 SQL Server 2012 中右键单击 DB 后,我使用在任务中生成脚本"选项获取脚本.但是,在每种情况下,.sql 文件的名称都是 spname.StoredProcedure.我希望名称为 spname.sql.同样,我不希望文件名是 database.spname.StoredProcedure,我希望它只是 spname.sql

解决方案

请查看以下 SQL 教程,了解如何

另外在生成脚本向导中,如果您配置如下图所示的选择选项,您将得到 sp 名称作为输出脚本文件名

I want to script all the stored procedures from SQL Server 2012 to Visual Studio 2012 as .sql files (in a different project). How do I do that? I want one .sql file for each stored procedure? I get the scripts using the Generate Scripts in Tasks option after right clicking DB in SQL Server 2012. However, the name of the .sql file is spname.StoredProcedure in each case. I want the name to be spname.sql. Again I don't want the file name to be database.spname.StoredProcedure, I want it to be just spname.sql

解决方案

Please check following SQL tutorial showing how to generate a separate script file for each stored procedure in a SQL Server database

The solution uses sp_Helptext stored procedure with SQL BCP command for generating create script for target SP and then create the export .sql file on the file system.

I hope it helps,

Additionally on generate script wizard, if you configure selection options as seen in below picture, you will get the sp name as the output script file name

这篇关于SQL Server 2012:如何将所有数据库存储过程编写成单独的 .sql 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)