SQL Server 与 Oracle DBMS_METADATA.GET_DDL 并行吗?
我正在寻找命令行或脚本化解决方案来从 SQL Server 2005+ 中为所有数据库对象提取 DDL:表、存储过程、视图、索引/索引、约束等。GUI 工具不感兴趣。
优先选择内置工具,因为它最能与 Oracle 的 DBMS_METADATA 工具相媲美。另外,更喜欢像 Oracle 那样简单的解决方案来获取 DDL - 例如,单行:
SELECT DBMS_METADATA.GET_DDL('TABLE', 'MY_TABLE') FROM DUAL
注意:在 SQL Server 2005 中获取过程的内容似乎很容易,但我找不到任何类似的参考资料其他对象(例如桌子)。
SELECT definition FROM Sys.sql_modules WHERE object_id = OBJECT_ID('MyProc')
提前致谢!
I'm looking for command line or scripted solutions to pull the DDL out of SQL Server 2005+ for all database objects: tables, stored procs, views, indices/indexes, constraints, etc. GUI tools are not of interest.
Preference is for built-in tools, since that would be the most comparable to Oracle's DBMS_METADATA stuff. Also, preference for a solution that is as simple as Oracle's for getting the DDL out - eg, a one liner:
SELECT DBMS_METADATA.GET_DDL('TABLE', 'MY_TABLE') FROM DUAL
Note: Getting things out for procedures in SQL Server 2005 seems easy, but I can't find any references to something similar for other objects (like tables).
SELECT definition FROM Sys.sql_modules WHERE object_id = OBJECT_ID('MyProc')
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Transact-SQL 语言不支持。客户端库 (SMO) 可以使用 Scripter 对象,请参阅 http://msdn.microsoft .com/en-us/library/ms162153.aspx。您可以使用 PowerShell 中的 SMO 作为脚本化解决方案。
SQL Management Studio 还有一个选项(右键单击数据库,转到“任务”,选择“生成脚本”),它在幕后使用 SMO 脚本编写器。
There is no support in the Transact-SQL language. The client libraries (SMO) can do it using a Scripter object, see example at http://msdn.microsoft.com/en-us/library/ms162153.aspx. You can use SMO from PowerShell as a scripted solution.
The SQL Management Studio also has an option (right click on a database, go to Tasks, select Generate Scripts), it uses an SMO Scripter under the covers.
我写了 SMOscript ,一个命令行工具,它使用SMO生成所有数据库对象的DDL文件。
I wrote SMOscript, a command-line tool which uses SMO to generate DDL files of all database objects.