SQL Server 2012 : How to script all database stored procedures into separate .sql files?

*爱你&永不变心* 提交于 2019-12-07 07:22:35

问题


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


回答1:


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




回答2:


As @Ivan_Starostin said:

Step one

Step two

Step three



来源:https://stackoverflow.com/questions/35719479/sql-server-2012-how-to-script-all-database-stored-procedures-into-separate-sq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!