我想大多数人都知道如何通过GUI(右键单击表,属性)来做到这一点,但是在T-SQL中完成此操作完全不错。

===============>>#1 票数:13 已采纳

CREATE TABLE #tmpSizeChar (
     table_name sysname ,
     row_count int,
     reserved_size varchar(50),
     data_size varchar(50),
     index_size varchar(50),
     unused_size varchar(50))                              

CREATE TABLE #tmpSizeInt (
     table_name sysname ,
     row_count int,
     reserved_size_KB int,
     data_size_KB int,
     index_size_KB int,
     unused_size_KB int)   

SET NOCOUNT ON
INSERT      #tmpSizeChar
EXEC      sp_msforeachtable 'sp_spaceused ''?'''     

INSERT INTO #tmpSizeInt (
        table_name,
        row_count,
        reserved_size_KB,
        data_size_KB,
        index_size_KB,
        unused_size_KB
        )
SELECT  [table_name],
        row_count,
        CAST(SUBSTRING(reserved_size, 0, PATINDEX('% %', reserved_size)) AS int)reserved_size,
        CAST(SUBSTRING(data_size, 0, PATINDEX('% %', data_size)) AS int)data_size,
        CAST(SUBSTRING(index_size, 0, PATINDEX('% %', index_size)) AS int)index_size,
        CAST(SUBSTRING(unused_size, 0, PATINDEX('% %', unused_size)) AS int)unused_size
FROM #tmpSizeChar   

/*
DROP TABLE #tmpSizeChar
DROP TABLE #tmpSizeInt
*/

SELECT * FROM #tmpSizeInt
ORDER BY reserved_size_KB DESC

===============>>#2 票数:0

看看这个,我知道它在2005年有效( Microsoft文档 ):

这是pubs DB


select *
from pubs.sys.database_files

返回size和max_size。

===============>>#3 票数:0

sp_spaceused tableName

其中tableName是您想知道的表的名称....

  ask by Nathan Bedford translate from so

未解决问题?本站智能推荐: