1. <i id='he3BK'><tr id='he3BK'><dt id='he3BK'><q id='he3BK'><span id='he3BK'><b id='he3BK'><form id='he3BK'><ins id='he3BK'></ins><ul id='he3BK'></ul><sub id='he3BK'></sub></form><legend id='he3BK'></legend><bdo id='he3BK'><pre id='he3BK'><center id='he3BK'></center></pre></bdo></b><th id='he3BK'></th></span></q></dt></tr></i><div id='he3BK'><tfoot id='he3BK'></tfoot><dl id='he3BK'><fieldset id='he3BK'></fieldset></dl></div>
      • <bdo id='he3BK'></bdo><ul id='he3BK'></ul>
      <tfoot id='he3BK'></tfoot>

      <small id='he3BK'></small><noframes id='he3BK'>

      1. <legend id='he3BK'><style id='he3BK'><dir id='he3BK'><q id='he3BK'></q></dir></style></legend>

        如何在 SQL Server 中使用 SMO 自动生成脚本?

        How to automate script generation using SMO in SQL Server?(如何在 SQL Server 中使用 SMO 自动生成脚本?)

        <i id='GQVvC'><tr id='GQVvC'><dt id='GQVvC'><q id='GQVvC'><span id='GQVvC'><b id='GQVvC'><form id='GQVvC'><ins id='GQVvC'></ins><ul id='GQVvC'></ul><sub id='GQVvC'></sub></form><legend id='GQVvC'></legend><bdo id='GQVvC'><pre id='GQVvC'><center id='GQVvC'></center></pre></bdo></b><th id='GQVvC'></th></span></q></dt></tr></i><div id='GQVvC'><tfoot id='GQVvC'></tfoot><dl id='GQVvC'><fieldset id='GQVvC'></fieldset></dl></div>

              <small id='GQVvC'></small><noframes id='GQVvC'>

            1. <legend id='GQVvC'><style id='GQVvC'><dir id='GQVvC'><q id='GQVvC'></q></dir></style></legend>
              • <bdo id='GQVvC'></bdo><ul id='GQVvC'></ul>
              • <tfoot id='GQVvC'></tfoot>
                  <tbody id='GQVvC'></tbody>

                  本文介绍了如何在 SQL Server 中使用 SMO 自动生成脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 SSMS 2008 中自动生成脚本(在 SSMS --> 任务 --> 生成脚本).我读到 SQL Server 2008 不支持数据库发布向导(包括 SQLPUBWIZ SCRIPT),但这种自动化可以在 SQL Server 2008 中使用 SMO 完成.我不知道 SMO 以及如何使用 SMO 执行此操作,所以您能给我一些建议(资源等)如何开始?

                  I would like to automate script generation (in SSMS --> Tasks --> Generate Scripts) in SSMS 2008. I have read that SQL Server 2008 does not support Database Publishing Wizard (including SQLPUBWIZ SCRIPT) but this automation can be done using SMO in SQL Server 2008. I don't have a clue about SMO and how to do this using SMO, so could you give me some advice (resources etc.) how to begin?

                  推荐答案

                  SMO 脚本编写的关键是 Scripter 类.所有其他工具(如 SSMS)都使用这个类来生成对象创建脚本.MSDN 上有一个示例用法:

                  The key to SMO scripting is the Scripter class. All other tools (like SSMS) use this class to generated object creation scripts. There is an example usage on MSDN:

                  { 
                     //Connect to the local, default instance of SQL Server. 
                    Server srv = new Server(); 
                  
                     //Reference the AdventureWorks2008R2 database.  
                    Database db = srv.Databases["AdventureWorks2008R2"]; 
                  
                     //Define a Scripter object and set the required scripting options. 
                    Scripter scrp = new Scripter(srv); 
                     scrp.Options.ScriptDrops = false; 
                     scrp.Options.WithDependencies = true; 
                  
                     //Iterate through the tables in database and script each one. Display the script. 
                     //Note that the StringCollection type needs the System.Collections.Specialized namespace to be included. 
                     Microsoft.SqlServer.Management.Sdk.Sfc.Urn[] smoObjects = new Microsoft.SqlServer.Management.Sdk.Sfc.Urn[1] ;
                     foreach (Table tb in db.Tables) {   
                        smoObjects[0] = tb.Urn; 
                        if (tb.IsSystemObject == false) { 
                           System.Collections.Specialized.StringCollection sc;
                           sc = scrp.Script(smoObjects); 
                           foreach ( string st in sc) { 
                              Console.WriteLine(st); 
                           } 
                        } 
                     } 
                  }
                  

                  这篇关于如何在 SQL Server 中使用 SMO 自动生成脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SQL query to group by day(按天分组的 SQL 查询)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                  sql group by versus distinct(sql group by 与不同)
                  How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)
                  Count number of records returned by group by(统计分组返回的记录数)
                  SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)
                  <legend id='7tuja'><style id='7tuja'><dir id='7tuja'><q id='7tuja'></q></dir></style></legend>

                          <tbody id='7tuja'></tbody>
                          <bdo id='7tuja'></bdo><ul id='7tuja'></ul>
                        • <small id='7tuja'></small><noframes id='7tuja'>

                        • <tfoot id='7tuja'></tfoot>
                        • <i id='7tuja'><tr id='7tuja'><dt id='7tuja'><q id='7tuja'><span id='7tuja'><b id='7tuja'><form id='7tuja'><ins id='7tuja'></ins><ul id='7tuja'></ul><sub id='7tuja'></sub></form><legend id='7tuja'></legend><bdo id='7tuja'><pre id='7tuja'><center id='7tuja'></center></pre></bdo></b><th id='7tuja'></th></span></q></dt></tr></i><div id='7tuja'><tfoot id='7tuja'></tfoot><dl id='7tuja'><fieldset id='7tuja'></fieldset></dl></div>