解决方法@H_404_6@
图形工具只是实际实现脚本的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);
}
}
}
}
还有更多的例子如何在各种其他网站上使用它.
//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); } } } }
还有更多的例子如何在各种其他网站上使用它.