--查询当前库中每个表所占空间 SELECT OBJECT_NAME(id) tablename , CASE WHEN reserved * 8 > 1024 THEN RTRIM(8 * reserved / 1024) + 'MB' ELSE RTRIM(reserved * 8) + 'KB' END DataReserve , CASE WHEN dpages * 8 > 1024 THEN RTRIM(8 * dpages / 1024) + 'MB' ELSE RTRIM(dpages * 8) + 'KB' END Used , CASE WHEN 8 * ( reserved - dpages ) > 1024 THEN RTRIM(8 * ( reserved - dpages ) / 1024) + 'MB' ELSE RTRIM(8 * ( reserved - dpages )) + 'KB' END unused , CASE WHEN ( 8 * dpages / 1024 - rows / 1024 * minlen / 1024 ) > 1024 THEN RTRIM(( 8 * dpages / 1024 - rows / 1024 * minlen / 1024 ) / 1024) + 'MB' ELSE RTRIM(( 8 * dpages / 1024 - rows / 1024 * minlen / 1024 )) + 'KB' END FREE , rows AS Rows_Count FROM sys.sysindexes WHERE indid = 1 AND status = 2066 -- status='18' ORDER BY reserved DESC