将查询从 SSMS 导出到文件 - 不是结果而是查询
我想将所有查询导出为单独的文件,以便将它们放入 Mercurial 源代码管理中,但我不知道如何将单独的查询导出为单独的文件,而不必打开每个文件,然后保存到文件夹,然后添加到项目中,或者一些同样复杂的过程。
我不介意必须单独添加每个文件,但是如何将它们作为单独的文件从数据库中取出,而不将它们全部打开并将每个文件另存为?表面上我希望它们以它们现在在数据库中的名称命名。
我可以使用数据库任务轻松地将所有内容转储到一个长文件中,但这并不是非常有用,不是吗?
我有 SSMS 2k5 和 2k8(以及 VS 2k5、2k8、2010)可以使用,有什么想法吗?
I want to export all my queries as individual files for purposes of putting them into mercurial source control, but I don't know how to export the individual queries as individual files without having to open each one, then save to the folder, then add into the project, or some equally convoluted process.
I wouldn't mind having to add each one individually, but how do I get them out of the database as individual files without opening them all and doing each one save as? Ostensibly I would like them named with the name they have in the database right now.
I could easily dump the whole lot into one long file using database tasks, but that's not really super helpful is it?
I have SSMS 2k5 and 2k8 (and VS 2k5, 2k8, 2010 to boot) to work with, any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
右键单击数据库。选择生成脚本。在最后一页。脚本到文件您可以选择单个文件或每个对象的文件
Right click on the database. Select Generate Script. On the last page. Script To file you can choose single file or file per object
当您在 SSMS 中编写数据库脚本时,您可以选择每个对象一个文件。
SMO 对于小应用程序非常有用,可以迭代
Red Gate SQL Compare(还有其他免费工具)等第三方工具,也可以编写脚本
When you script a database in SSMS you have the option of one file per objects.
SMO is useful with a small app to iterate through
Third party tools like Red Gate SQL Compare (there are other free tools) can script too
我会编写一个小型 C# 程序,它通过 SMO 提取数据库对象并按照您想要的方式将它们存储在文件系统中。
I would write a small C# program which extracts your database object via SMO and stores them in your filesystem the way you want.
编写将定义作为文本提取到结果中的存储过程相当容易。 sp_helptext 可以用作启动。
您可以使用 PowerShell 将输出写入文件系统。
听起来这似乎非常适合“真正简单的数据字典”codeplex 项目。 链接文本
It is rather easy to write stored procedures which fetches the definition into the result as text. sp_helptext could be used as start.
Than you can use PowerShell to write the Output to the file system.
It sounds as if this would fit rather good into the Really Simple Data Dictionary codeplex project. link text