Используйте этот скрипт для отключения всех индексов
-- Disable All Indices
DECLARE @Script NVARCHAR(MAX)
DECLARE curIndices CURSOR FAST_FORWARD READ_ONLY FOR
SELECT 'ALTER INDEX ' + QUOTENAME(indices.name) + ' ON ' + QUOTENAME(SCHEMA_NAME(tableNames.schema_id))+'.'+ QUOTENAME(tableNames.name) + ' DISABLE'
FROM
sys.indexes indices INNER JOIN
sys.tables tableNames ON indices.object_id = tableNames.object_id
WHERE
indices.type_desc = 'NONCLUSTERED' AND
indices.name IS NOT NULL AND
indices.is_disabled = 0;
OPEN curIndices
FETCH NEXT FROM curIndices INTO @Script
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @Script
EXECUTE sp_executesql @Script
FETCH NEXT FROM curIndices INTO @Script
END
CLOSE curIndices
DEALLOCATE curIndices
Используйте этот скрипт для перестройки (включения) всех индексов
-- Rebuild All Indices
DECLARE @Script NVARCHAR(MAX)
DECLARE curIndices CURSOR FAST_FORWARD READ_ONLY FOR
SELECT 'ALTER INDEX ' + QUOTENAME(indices.name) + ' ON ' + QUOTENAME(SCHEMA_NAME(tableNames.schema_id))+'.'+ QUOTENAME(tableNames.name) + ' REBUILD'
FROM
sys.indexes indices INNER JOIN
sys.tables tableNames ON indices.object_id = tableNames.object_id
WHERE
indices.type_desc = 'NONCLUSTERED' AND
indices.name IS NOT NULL AND
indices.is_disabled = 1;
OPEN curIndices
FETCH NEXT FROM curIndices INTO @Script
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @Script
EXECUTE sp_executesql @Script
FETCH NEXT FROM curIndices INTO @Script
END
CLOSE curIndices
DEALLOCATE curIndices
If you're using Rails (not just plain Ruby), a slightly shorter method is
def foo(options = {})
options.reverse_merge! { ... defaults ... }
end
This has the added advantage of allowing you to do multiple lines a tad bit more cleanly:
def foo(options = {})
options.reverse_merge!(
:some_default => true,
:other_default => 5
)
end
def foo(options = {})
options = { ... defaults ... }.merge(options)
end
Обычно лучше всего инкапсулировать безопасные значения по умолчанию в хэше, объявленном как константа. Например:
require 'ostruct'
require 'ostruct'
class Tiger < OpenStruct
DEFAULTS = {
:num_stripes => 12,
:max_speed => 43.2
}.freeze
def initialize(options = { })
super(DEFAULTS.merge(options))
end
end
tiger = Tiger.new(:max_speed => 19.95)
puts tiger.max_speed
puts tiger.num_stripes
Важно отметить, что при объединении объектов Hash ключи String и Symbol различны и не будут объединяться, как вы могли ожидать. В среде Rails вы всегда можете преобразовать одно в другое, используя Hash # symbolize_keys или объявив их как HashWithIndifferentAccess, что позволяет устранить разницу.