我在 C# 中构建了一个简单的实用程序,它使用 Microsoft.SqlServer.Management.Smo对象来导出数据库模式。在我添加全文索引之前,这一直很好用。
当它导出用于创建全文索引的 SQL 时,它不包括在索引中定义的列。例如,假设我有一个名为“Recipes”的表,其中 2 列包含在名为“RecipeName”“Description”的 FT 索引中。使用我的实用程序转储模式会生成以下 SQL:
CREATE FULLTEXT INDEX ON [dbo].[Recipes]
KEY INDEX [PK_Recipes]ON ([ft], FILEGROUP [PRIMARY])
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
我希望被抛弃的是这个(注意列):
CREATE FULLTEXT INDEX ON [dbo].[Recipes](
[Description] LANGUAGE [English],
[RecipeName] LANGUAGE [English]
)
KEY INDEX [PK_Recipes]ON ([ft], FILEGROUP [PRIMARY])
WITH (CHANGE_TRACKING = AUTO, STOPLIST = SYSTEM)
这是从数据库文件生成模式的 C#:
static void GenerateScript(string sourceDbPath, string destinationScriptPath)
{
try
{
string connString = string.Format(@"Data Source=.;AttachDbFilename={0};Integrated Security=True;User Instance=True", sourceDbPath);
SqlConnection sqlConn = new SqlConnection(connString);
ServerConnection serverConn = new ServerConnection(sqlConn);
Server server = new Server(serverConn);
Database database = server.Databases[sourceDbPath];
Transfer transfer = new Transfer(database);
ScriptingOptions options = new ScriptingOptions();
options.AppendToFile = false; // Overwrite file
options.ClusteredIndexes = true;
options.Indexes = true;
options.DriAll = true;
options.Triggers = true;
options.Bindings = true;
options.Default = true;
options.IncludeDatabaseContext = false;
options.IncludeHeaders = true;
options.FullTextIndexes = true;
options.SchemaQualify = true;
options.SchemaQualifyForeignKeysReferences = true;
options.ScriptSchema = true;
options.ScriptData = false;
options.ScriptDrops = false;
options.FileName = destinationScriptPath;
transfer.Options = options;
transfer.CopyAllFullTextCatalogs = true;
transfer.CopyAllFullTextStopLists = true;
transfer.CopyAllTables = true;
transfer.ScriptTransfer();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
Environment.Exit(-1);
}
}
谁能发现我错过了什么?