解决方法
图形工具只是实际实现脚本的SMO类的一个包装,就像
Scripter类.有一个示例使用MSDN中的SMO在数据库中编写所有表:
Scripting:
//Connect to the local,default instance of sql Server. { Server srv = default(Server); srv = new Server(); //Reference the AdventureWorks database. Database db = default(Database); db = srv.Databases("AdventureWorks"); //Define a Scripter object and set the required scripting options. Scripter scrp = default(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. Table tb = default(Table); Urn[] smoObjects = new Urn[2]; foreach ( tb in db.Tables) { smoObjects = new Urn[1]; smoObjects(0) = tb.Urn; if (tb.IsSystemObject == false) { StringCollection sc = default(StringCollection); sc = scrp.Script(smoObjects); string st = null; foreach ( st in sc) { Console.WriteLine(st); } } } }
还有更多的例子如何在各种其他网站上使用它.
原文地址:https://www.jb51.cc/mssql/75072.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。