MSSQL, 테이블 및 인덱스 사이즈 구하기, Table and Index size in SQL Server

DataBase/MS-SQL|2019. 11. 5. 14:09
반응형
create table #t
(
  name nvarchar(128),
  rows varchar(50),
  reserved varchar(50),
  data varchar(50),
  index_size varchar(50),
  unused varchar(50)
)

declare @id nvarchar(128)
declare c cursor for
select '[' + sc.name + '].[' + s.name + ']' FROM sysobjects s INNER JOIN sys.schemas sc ON s.uid = sc.schema_id where s.xtype='U'

open c
fetch c into @id

while @@fetch_status = 0 begin

  insert into #t
  exec sp_spaceused @id

  fetch c into @id
end

close c
deallocate c

select * from #t
order by convert(int, substring(data, 1, len(data)-3)) desc

drop table #t

 

 

참고 URL : https://stackoverflow.com/questions/316831/table-and-index-size-in-sql-server

댓글()