获得Sql Server 2005 中任意对象创建脚本的C#实现
Microsoft.SqlServer.Management.Common.ServerConnection conn = new Microsoft.SqlServer.Management.Common.ServerConnection(
new System.Data.SqlClient.SqlConnection(@"server=server;uid=sa;pwd=sa;database=BigSmartDB"));//一个数据库连接字符串
Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(conn);
Microsoft.SqlServer.Management.Smo.Database db = server.Databases["DB1"];
Microsoft.SqlServer.Management.Smo.Table tb = db.Tables["table1"];
System.Collections.Specialized.StringCollection sc = tb.Indexes["IX_index1"].Script();
string mmm = "";
foreach (String s in sc)
{
mmm += s + @"
";
}
MessageBox.Show(mmm);