如何按SQL Server中的行数调整表大小

时间:2021-01-19 01:54:19

I have a table where I want to get size of the number records based on byte In SQL Server:

我有一个表,我希望根据字节在SQL Server中获取数字记录的大小:

如何按SQL Server中的行数调整表大小

1 个解决方案

#1


0  

The only answer related to this question that I can suggest is this:

我可以建议与此问题相关的唯一答案是:

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';

Edit
You can get length of your data in a field by using DATALENGTH like this:

编辑您可以使用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);

#1


0  

The only answer related to this question that I can suggest is this:

我可以建议与此问题相关的唯一答案是:

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';

Edit
You can get length of your data in a field by using DATALENGTH like this:

编辑您可以使用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);