2016-01-16 54 views
0

我有一個表,我想基於字節 在SQL Server中得到的數量記錄尺寸大小表由行數:如何在SQL Server

enter image description here

+0

你想知道給定表的字節大小,或者你要計算的記錄數。 –

+1

看看這個問題http://stackoverflow.com/questions/7892334/get-size-of-all-tables-in-database –

+0

請重寫這個問題,因爲這個問題不夠清楚。 – shadow

回答

0

相關的唯一答案this question,我可以建議是這樣的:

SELECT 
    s.name AS SchemaName, 
    t.name AS TableName, 
    p.rows AS RowCounts, 
    a.total_pages * 8 AS TotalSpaceKB, 
    a.used_pages * 8 AS UsedSpaceKB, 
    a.total_pages * 8/p.rows AS eachRowTotalSpaceKB, 
    a.used_pages * 8/p.rows AS eachRowUsedSpaceKB, 
    a.total_pages * 8/p.rows * (select * from dbo.PictureTable where SchoolCode=1001) AS queryTotalSpaceKB, 
    a.used_pages * 8/p.rows * (select * from dbo.PictureTable where SchoolCode=1001) AS queryTotalSpaceKB 
FROM 
    sys.tables t 
INNER JOIN  
    sys.indexes i ON t.OBJECT_ID = i.object_id 
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id 
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id 
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id 
WHERE 
    s.name = 'dbo' AND 
    t.name = 'PictureTable'; 

編輯
您可以通過使用DATALENGTH這樣讓您的數據的長度在一個領域:

SELECT SUM(DATALEGTH(PictureTable_ID)) + SUM(DATALEGTH(Groupcourses_ID)) +SUM(DATALEGTH(per_ID)) + SUM(DATALEGTH(School_ID)) + SUM(DATALEGTH(AcademicYear_ID)) + SUM(DATALEGTH(PictureTable_Description)) + SUM(DATALEGTH(SchoolCode)) As rowSizes 
FROM PictureTable 
WHERE (SchoolCode = 1001); 
+0

是所有權重表 - 我去自定義號碼記錄權重表 –

+0

如果您想知道每行的數據長度我添加一個編輯信息到我的答案;)。 –

+0

Thanks is Real Solutions –