SELECT sc.name +'.'+ ta.name TableName
,SUM(pa.rows) RowCnt
FROM sys.tables ta
INNER JOIN sys.partitions pa
ON pa.OBJECT_ID = ta.OBJECT_ID
INNER JOIN sys.schemas sc
ON ta.schema_id = sc.schema_id
WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY sc.name,ta.name
ORDER BY SUM(pa.rows) DESC


mssql 테이블 목록과 각 테이블의 데이터수 쿼리

추가)
1. 테이블 목록 가져오기
 select distinct table_name from information_schema.columns
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE 1=1
--AND TABLE_TYPE ='VIEW'
AND TABLE_TYPE ='BASE TABLE'
--AND TABLE_NAME NOT LIKE '%TEST%'
AND TABLE_SCHEMA = 'dbo'
ORDER BY TABLE_NAME 
2. 프로시져 목록 가져오기
 select distinct specific_name from INFORMATION_SCHEMA.PARAMETERS

출처:http://blog.sqlauthority.com/2010/09/08/sql-server-find-row-count-in-table-find-largest-table-in-database-part-2/


+ Recent posts