--1.新增TEMP TABLE create table #temptable ([name] varchar(50),[rows] bigint,resverved varchar(50),data varchar(50),index_size varchar(50),unused varchar(50)) --2.執行查詢結果 select 'insert into #temptable exec sp_spaceused '''+name+'''' from sysobjects where objectproperty(id,'IsUserTable')=1 --3. 方便查看 update #temptable set resverved=left(resverved,charindex(' ',resverved)-1), data=left(data,charindex(' ',data)-1), index_size=left(index_size,charindex(' ',index_size)-1), unused=left(unused,charindex(' ',unused)-1) --4.查詢結果 select * from #temptable order by cast(resverved as bigint) desc,cast(data as bigint) desc ---5. 爲了方便比較,彙總 select convert(char(5),sum(cast(data as bigint))/1024/1024)+'GB' from #temptable select convert(char(5),sum(cast(unused as bigint))/1024)+'MB' from #temptable select convert(char(5),sum(cast(resverved as bigint))/1024)+'MB' from #temptable ---有了上面的結果,對每一個表進行容量回收,清楚垃圾數據,還能夠考慮分離數據庫。 --drop table #temptable