public static EnableIndex ( ObjectName tableName, string indexName ) : |
||
tableName | ObjectName | |
indexName | string | |
Результат |
public static IDisposable PrepareTableForBatchLoadScope(ITable table, bool disableForeignKeys, bool disableMultipleIndexes, bool disableUniqueIndexes) { SafeConsole.WriteColor(ConsoleColor.Magenta, table.Name + ":"); Action onDispose = () => SafeConsole.WriteColor(ConsoleColor.Magenta, table.Name + ":"); if (disableForeignKeys) { SafeConsole.WriteColor(ConsoleColor.DarkMagenta, " NOCHECK Foreign Keys"); Executor.ExecuteNonQuery("ALTER TABLE {0} NOCHECK CONSTRAINT ALL".FormatWith(table.Name)); onDispose += () => { SafeConsole.WriteColor(ConsoleColor.DarkMagenta, " RE-CHECK Foreign Keys"); Executor.ExecuteNonQuery("ALTER TABLE {0} WITH CHECK CHECK CONSTRAINT ALL".FormatWith(table.Name)); }; } if (disableMultipleIndexes) { var multiIndexes = GetIndixesNames(table, unique: false); if (multiIndexes.Any()) { SafeConsole.WriteColor(ConsoleColor.DarkMagenta, " DISABLE Multiple Indexes"); multiIndexes.Select(i => SqlBuilder.DisableIndex(table.Name, i)).Combine(Spacing.Simple).ExecuteLeaves(); Executor.ExecuteNonQuery(multiIndexes.ToString(i => "ALTER INDEX [{0}] ON {1} DISABLE".FormatWith(i, table.Name), "\r\n")); onDispose += () => { SafeConsole.WriteColor(ConsoleColor.DarkMagenta, " REBUILD Multiple Indexes"); multiIndexes.Select(i => SqlBuilder.EnableIndex(table.Name, i)).Combine(Spacing.Simple).ExecuteLeaves(); }; } } if (disableUniqueIndexes) { var uniqueIndexes = GetIndixesNames(table, unique: true); if (uniqueIndexes.Any()) { SafeConsole.WriteColor(ConsoleColor.DarkMagenta, " DISABLE Unique Indexes"); uniqueIndexes.Select(i => SqlBuilder.DisableIndex(table.Name, i)).Combine(Spacing.Simple).ExecuteLeaves(); onDispose += () => { SafeConsole.WriteColor(ConsoleColor.DarkMagenta, " REBUILD Unique Indexes"); uniqueIndexes.Select(i => SqlBuilder.EnableIndex(table.Name, i)).Combine(Spacing.Simple).ExecuteLeaves(); }; } } Console.WriteLine(); onDispose += () => Console.WriteLine(); return(new Disposable(onDispose)); }