【问题标题】:Difference between sp_spaceused and DataLength SQL Serversp_spaceused 和 DataLength SQL Server 之间的区别
【发布时间】:2009-04-20 13:43:23
【问题描述】:

当我使用 SP_SpaceUsed N'' 时,我有一个单行表,它给我的数据为 16 KB

当我使用 dataLength 时:-

选择 ClientID , (0 + isnull(datalength(ClientID), 1) + isnull(数据长度(LeadID),1)+ isnull(数据长度(公司名称),1)+ isnull(数据长度(网站),1)+ isnull(datalength(EmployeeCount), 1) + isnull(数据长度(收入),1)+ isnull(数据长度(地址),1)+ isnull(数据长度(城市),1)+ isnull(数据长度(状态),1)+ isnull(数据长度(邮编), 1) + isnull(数据长度(CountryID), 1) + isnull(数据长度(电话),1)+ isnull(数据长度(传真),1)+ isnull(数据长度(时区),1)+ isnull(数据长度(SicNo),1)+ isnull(数据长度(SicDesc),1)+ isnull(数据长度(研究分析),1)+ isnull(数据长度(SourceID), 1) + isnull(数据长度(BasketID), 1) + isnull(datalength(PipelineStatusID), 1) + isnull(数据长度(SurveryID),1)+ isnull(数据长度(NextCallDt),1)+ isnull(数据长度(CurrentRecStatus),1)+ isnull(数据长度(AssignedUserID), 1) + isnull(数据长度(AssignedDate), 1) + isnull(数据长度(TotValueAmt),1)+ isnull(数据长度(删除),1)+ isnull(数据长度(发布),1)+ isnull(数据长度(LegendID),1)+ isnull(数据长度(Inserted_Date), 1) + isnull(数据长度(Inserted_By),1)+ isnull(数据长度(Updated_Date), 1) + isnull(数据长度(Updated_By),1)) as rowsize from TempLeadHeader order by rowsize desc

它给出了 rowsize 167 我猜这是以字节为单位的

我想知道为什么结果会出现这种差异

提前致谢

【问题讨论】:

    标签: sql-server sql-server-2005 datalength


    【解决方案1】:

    sp_spaceused 计算页面使用的空间,即 8k 块。 请记住,表还包括占用空间的索引等内容。更不用说页面上的数据永远不会满,除非填充因子是 100%

    datalength 会告诉你你的列有多少字节

    【讨论】:

      【解决方案2】:

      您将 1 行与一个表进行比较,您必须对每一行进行求和,即使那样它也不会相同,因为您没有显示标题信息和索引数据

      你也可以这样做

      dbcc showcontig ('TempLeadHeader') with tableresults
      

      然后查看最小、最大和平均记录大小列

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-02-18
        • 1970-01-01
        • 1970-01-01
        • 2013-08-21
        • 2021-05-17
        • 1970-01-01
        • 1970-01-01
        • 2020-12-10
        相关资源
        最近更新 更多