以编程方式获取所有存储过程的简单方法 [英] Simple way to programmatically get all stored procedures
问题描述
是否可以使用C#从SQL Server 2005 Express数据库中获取存储过程?我想以可以使用SQL Server Management Studio编写脚本的相同方式导出所有这些数据,而不必安装GUI.
Is there a way to get stored procedures from a SQL Server 2005 Express database using C#? I would like to export all of this data in the same manner that you can script it our using SQL Server Management Studio, without having to install the GUI.
我已经看到了一些通过PowerShell执行操作的引用,但最终我真正想要的是C#控制台应用程序.
I've seen some references to do thing via the PowerShell but in the end a C# console app is what I really want.
要澄清....
To clarify....
我想编写出存储过程的脚本.通过从sys.procedures中选择* *
列出的列表很有帮助,但最后我需要将每一个脚本编写出来.
I'd like to script out the stored procedures. The list via the Select * from sys.procedures
is helpful, but in the end I need to script out each of these.
推荐答案
只需从SYS.PROCEDURES中读取SELECT NAME的输出,然后为每个存储过程调用EXEC sp_HelpText SPNAME,您将获得一条记录集,其中包含一行每行文字.
Just read the output of SELECT NAME from SYS.PROCEDURES , then call EXEC sp_HelpText SPNAME for each stored procedure, you'll get a record set with one line of text per row.
这篇关于以编程方式获取所有存储过程的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!