Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL Server 2008:disabilita l'indice su una particolare partizione di tabella

Gli indici sono in genere sullo schema di partizione. Per lo scenario di cui stai parlando puoi effettivamente caricare una nuova tabella con il batch (struttura identica, nome diverso) e quindi utilizzare il comando SWITCH per aggiungere questa tabella come nuova partizione nella tabella esistente.

Ho incluso il codice che utilizzo per eseguire questa operazione, dovrai modificarlo in base ai nomi delle tue tabelle:

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;