Un'interessante novità di SQL Server 2005 è quella di poter disabilitare un indice.
Può essere utile nei casi in cui si voglia mettere offline un indice mantenendo i metadati all'interno del database.
La domanda del post è: posso disabilitare un indice clustered?
La risposta: si! Ma a-t-t-e-n-z-i-o-n-e: equivale a disabilitare la tabella stessa e quindi a renderla irraggiungibile!
-- eseguo test sul db temp
use tempdb
GO
-- creazione di una tabella di test
create table test
(
idRecord int identity(1,1),
valore varchar(20),
CONSTRAINT PK_test PRIMARY KEY NONCLUSTERED (idRecord)
)
GO
-- creazione indice clustered sulla tabella
create clustered index idx_valore on test(valore)
GO
-- inserimento dati di prova
insert test values ('a')
insert test values ('b')
insert test values ('c')
insert test values ('d')
-- vedo la tabella
select * from test
-- ATTENZIONE: disabilito l'indice clustered!
-- (attenzione al warning che ci da SQL Server)
ALTER INDEX idx_valore ON test DISABLE
GO
-- vedo la tabella (NON funziona!!!)
select * from test
/*
Questo l'errore:
Msg 8655, Level 16, State 1, Line 3
The query processor is unable to produce a plan because the index 'idx_valore' on table or view 'test' is disabled.
*/
-- ricostruisco l'indice (il contrario di DISABLE è REBUILD!)
ALTER INDEX idx_valore ON test REBUILD
GO
-- vedo la tabella (ok)
select * from test
-- faccio pulizia
drop table test
GO
Spesso non si ricorda che un report, con qualsiasi
strumento esso venga costruito, rappresenta dati in un particolare e preciso
momento.
Ovvero uno stato che può, eventualmente, cambiare
un attimo dopo.
Per questo motivo penso sia importante fornire
sempre informazioni circa la data di escuzione e l'utente che ha eseguito il
report.
Personalmente risolvo questa esigenza grazie al
footer del report, alcune variabili globali e tre oggetti textBox che valorizzo
così:
= "Data esecuzione: " &
Globals!ExecutionTime.ToLongDateString & " : " &
Globals!ExecutionTime.ToLongTimeString
= "Utente: " & User!UserID
=
"Pag. " & Globals!PageNumber & " di " &
Globals!TotalPages
... oltre
questo imposto sempre il Language del report in maniera opportuna (così che le
date vengano formattate nelle corrette impostazioni internazionali)
;-)