Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

SQL Server 2008:Index für eine bestimmte Tabellenpartition deaktivieren

Indizes befinden sich normalerweise im Partitionsschema. Für das Szenario, von dem Sie sprechen, können Sie tatsächlich eine neue Tabelle mit dem Stapel laden (identische Struktur, anderer Name) und diese Tabelle dann mit dem SWITCH-Befehl als neue Partition in Ihre vorhandene Tabelle einfügen.

Ich habe Code eingefügt, den ich verwende, um dies auszuführen, Sie müssen ihn basierend auf Ihren Tabellennamen ändern:

DECLARE @importPart int
DECLARE @hourlyPart int

SET @importPart = 2 -- always, so long as the Import table is only made up of 1 partition

-- get the Hourly partition
SELECT 
    @hourlyPart = MAX(V.boundary_id) + 1
FROM 
    sys.partition_range_values V
JOIN    sys.partition_functions F
    ON  V.function_id = F.function_id
    AND F.name = 'pfHourly'

ALTER TABLE Import
SWITCH PARTITION @importPart
TO Hourly PARTITION @hourlyPart;