까막군's 주접 블로그

검색 :
RSS 구독 : 글 / 댓글 / 트랙백 / 글+트랙백

[MSSQL] Table 별 용량 및 Row 수 조회

2008/12/23 10:51, 글쓴이 까막군


-- 테이블별 사용 용량
SELECT table_name = convert(varchar(30), min(o.name))
 , table_size = ltrim(str(sum(cast(reserved as bigint)) * 8192 / 1024.,15,0) + 'KB')
FROM sysindexes i
  INNER JOIN
  sysobjects o
  ON (o.id = i.id)
WHERE i.indid IN (0, 1, 255)
AND  o.xtype = 'U'
GROUP BY i.id

-- 용량별 소팅
SELECT table_name = convert(varchar(30), min(o.name))
 , table_size = convert(int, ltrim(str(sum(cast(reserved as bigint)) * 8192 / 1024., 15, 0))), UNIT = 'KB'
FROM sysindexes i
  INNER JOIN
  sysobjects o
  ON (o.id = i.id)
WHERE i.indid IN (0, 1, 255)
AND  o.xtype = 'U'
GROUP BY i.id
ORDER BY table_size DESC

-- 테이블별 Row 수
SELECT o.name
 , i.rows
FROM sysindexes i
  INNER JOIN
  sysobjects o
  ON i.id = o.id
WHERE i.indid < 2
AND  o.xtype = 'U'
ORDER BY i.id

MSSQL 2000 , 2005 모두 사용가능..

버그 수정 ( 09.02.04)
- reserved 컬럼을 BigInt 형으로 Cast.. (Int overflow 오류 수정)

크리에이티브 커먼즈 라이센스
Creative Commons License
2008/12/23 10:51 2008/12/23 10:51

맨 위로