SQL Server sp_spaceused 和 DataLength 之间的区别

发布于 2024-07-17 07:22:41 字数 1467 浏览 7 评论 0原文

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

,当我使用 dataLength 时,如下所示:-

select ClientID , 
(0 + isnull(datalength(ClientID), 1) + 
isnull(datalength(LeadID), 1) + 
isnull(datalength(Company_Name), 1) + 
isnull(datalength(Website), 1) + 
isnull(datalength(EmployeeCount), 1) + 
isnull(datalength(Revenue), 1) +
 isnull(datalength(Address), 1) + 
isnull(datalength(City), 1) + 
isnull(datalength(State), 1) + 
isnull(datalength(ZipCode), 1) + 
isnull(datalength(CountryID), 1) + 
isnull(datalength(Phone), 1) + 
isnull(datalength(Fax), 1) + 
isnull(datalength(TimeZone), 1) + 
isnull(datalength(SicNo), 1) + 
isnull(datalength(SicDesc), 1) +
 isnull(datalength(ResearchAnalysis), 1) + 
isnull(datalength(SourceID), 1) + 
isnull(datalength(BasketID), 1) + 
isnull(datalength(PipelineStatusID), 1) + 
isnull(datalength(SurveryID), 1) + 
isnull(datalength(NextCallDt), 1) + 
isnull(datalength(CurrentRecStatus), 1) +
 isnull(datalength(AssignedUserID), 1) + 
isnull(datalength(AssignedDate), 1) + 
isnull(datalength(TotValueAmt), 1) + 
isnull(datalength(Remove), 1) + 
isnull(datalength(Release), 1) + 
isnull(datalength(LegendID), 1) + 
isnull(datalength(Inserted_Date), 1) +
 isnull(datalength(Inserted_By), 1) + 
isnull(datalength(Updated_Date), 1) + 
isnull(datalength(Updated_By), 1)) 
as rowsize from TempLeadHeader order by rowsize desc

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

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

提前致谢

I have a table with single Row when i use SP_SpaceUsed N'<TableName>' it gives me data as 16 KB

and when I use dataLength something like this:-

select ClientID , 
(0 + isnull(datalength(ClientID), 1) + 
isnull(datalength(LeadID), 1) + 
isnull(datalength(Company_Name), 1) + 
isnull(datalength(Website), 1) + 
isnull(datalength(EmployeeCount), 1) + 
isnull(datalength(Revenue), 1) +
 isnull(datalength(Address), 1) + 
isnull(datalength(City), 1) + 
isnull(datalength(State), 1) + 
isnull(datalength(ZipCode), 1) + 
isnull(datalength(CountryID), 1) + 
isnull(datalength(Phone), 1) + 
isnull(datalength(Fax), 1) + 
isnull(datalength(TimeZone), 1) + 
isnull(datalength(SicNo), 1) + 
isnull(datalength(SicDesc), 1) +
 isnull(datalength(ResearchAnalysis), 1) + 
isnull(datalength(SourceID), 1) + 
isnull(datalength(BasketID), 1) + 
isnull(datalength(PipelineStatusID), 1) + 
isnull(datalength(SurveryID), 1) + 
isnull(datalength(NextCallDt), 1) + 
isnull(datalength(CurrentRecStatus), 1) +
 isnull(datalength(AssignedUserID), 1) + 
isnull(datalength(AssignedDate), 1) + 
isnull(datalength(TotValueAmt), 1) + 
isnull(datalength(Remove), 1) + 
isnull(datalength(Release), 1) + 
isnull(datalength(LegendID), 1) + 
isnull(datalength(Inserted_Date), 1) +
 isnull(datalength(Inserted_By), 1) + 
isnull(datalength(Updated_Date), 1) + 
isnull(datalength(Updated_By), 1)) 
as rowsize from TempLeadHeader order by rowsize desc

it gives rowsize 167 i guess this is in bytes

I would like to know why this difference is coming up in the result

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神妖 2024-07-24 07:22:41

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

数据长度会告诉您列有多少字节

sp_spaceused counts the space used by pages, which are 8k blocks.
Remember that a table also includes things like indexes that take up space too. not to mention that data on pages are never full unless the fill factor is 100%

datalength will tell you how many bytes your column is

凉世弥音 2024-07-24 07:22:41

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

您也可以执行类似的操作

dbcc showcontig ('TempLeadHeader') with tableresults

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

you compared 1 row against a table you would have to sum it for every row and even then it won't be the same because you are not showing header information and index data

you can also do something like this

dbcc showcontig ('TempLeadHeader') with tableresults

Then look at min, max and average recordsize columns

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文