以编程方式为数据库中的所有对象生成脚本 [英] Programmatically generate script for all objects in a database
问题描述
对于为使用Microsoft SQL Server的应用程序生成安装程序的自动安装程序生成,我目前正在评估是否可以进行以下操作:
For an automated setup build that generates the setup for an application which uses Microsoft SQL Server, I am currently evaluating whether the following is possible:
我想以编程方式(CMD脚本或C#代码)执行功能 生成脚本可以从Microsoft SQL Server Management Studio 2008访问。
I want to programmatically (CMD script or C# code) execute the function "Generate Scripts" on a database that is accessible from Microsoft SQL Server Management Studio 2008.
即调用一些代码,并将指定数据库的所有对象(表,SP,约束等)作为SQL脚本。
I.e. call some code and have all the objects (tables, SPs, constraints, etc.) of a specified database as an SQL script.
当前,我只需要结构,
Currently, I only need the structure, not the data.
问题:是否可以实现这一目标?
Question: Is it possible to achieve this goal?
推荐答案
我写了 SMOscript (命令行)
MSSQL的生成脚本功能通常不考虑引用和依赖性来确定序列的顺序。对象(至少在2000年和2005年就是这种情况)
The Generate Scripts function of MSSQL typically does not consider references and dependencies to determine the sequence of objects (at least that was the case with 2000 and 2005)
这篇关于以编程方式为数据库中的所有对象生成脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!