Uno script per compattare tutti i datafiles rilasciando spazio
a scritp to compact alla datfiles with space relesing at the end
USE Database
GO
DECLARE @fileid as int
DECLARE @name as varchar(50)
DECLARE contact_cursor CURSOR FOR
SELECT file_id, name
FROM sys.database_files;
OPEN contact_cursor;
FETCH NEXT FROM contact_cursor
INTO @fileid, @name;
WHILE @@FETCH_STATUS = 0
BEGIN
--Shrink datafile. Rilascia tutto lo spazio disponibile alla fine del file sistema operativo.
DBCC SHRINKFILE (@fileid, TRUNCATEONLY);
FETCH NEXT FROM contact_cursor
INTO @fileid, @name;
END
CLOSE contact_cursor;
DEALLOCATE contact_cursor;