상세 컨텐츠

본문 제목

MS SQL Server DB 사용량, Table Size

DataBase/SQL Server

by 탑~! 2021. 1. 4. 16:07

본문

--사용량 체크



USE [DB_Name]


select  'DB_Size' Gubun, sum(size)/128  Size_MB from sys.database_files     where [type] in ( 0, 2, 4 )
union all
select  'LOG_Size',      sum(size)/128          from sys.database_files     where [type] in ( 1,3 )
union all
select 'SpaceUsed',      sum(total_pages)/128   from sys.allocation_units



-- Table Size

select  max(b.name)         TableName
       ,cast((sum(a.reserved) * 8192.0 / 1024   ) as numeric(18,0)) TableSize_KB
       ,cast((sum(a.reserved) * 8192.0 / 1048576) as numeric(18,0)) TableSize_MB
from    SysIndexes a
        inner join SysObjects b on (b.id = a.id)
where   a.indid in (0, 1, 255)
and     b.xtype = 'U'
group by a.id
 
order by sum(a.reserved) desc



-- TABLE 건수

select  b.name
       ,a.rows
from    sysindexes a
        inner join  sysobjects b on (b.id = a.id)
where   a.indid     < 2
and     b.xtype     = 'U'
 
order by a.rows desc

'DataBase > SQL Server' 카테고리의 다른 글

탭문자 확인 및 제거  (0) 2021.01.04
mssql 비용이 많이드는 쿼리 검색  (0) 2021.01.04
SQL Server Lock 확인 및 IP추적  (0) 2021.01.04
Sql Server 페이징 처리  (0) 2021.01.04
SQL Server 인덱스 리빌드  (0) 2021.01.04

관련글 더보기