简体   繁体   English

如何在Sql Server中计算表的行明智大小?

[英]How to calculate row wise size of table in Sql server?

My table having 80K+ records. 我的桌子有80K +条记录。 I need to calculate each and every row size. 我需要计算每个行的大小。 This sum of row size must be same as table size 行大小的总和必须与表大小相同

This is too long for a comment. 这个评论太长了。

There is very little relationship between the size of table and the size of a row. 表的大小和行的大小之间几乎没有关系。 Tables sizes are really measured in numbers of pages that the table occupies (and perhaps associated indexes as well). 表的大小实际上是根据表所占用的页面数(也可能是相关索引)来衡量的。 Page sizes can be converted to bytes. 页面大小可以转换为字节。

Record sizes (and you can look into [ datalength()][1] ) return sizes in bytes, which is a more typical measure of size on a computer. 记录大小(您可以查看[ datalength()][1] )以字节为单位的返回大小,这是计算机上更典型的大小度量。

Why are these not related very much? 为什么这些关系不大? Here are three reasons I can readily think of: 我很容易想到以下三个原因:

  • Pages have over head needed by the database. 页面具有数据库所需的开销。
  • Pages may not be completely filled. 页面可能未完全填满。
  • The size of the table should probably include associated index structures, but that is not part of the records. 表的大小可能应该包括关联的索引结构,但这不是记录的一部分。

In particular, you might have one 10-byte record on an 8k page. 特别是,您可能在8k页上只有一个10字节的记录。 Or, you might have 800 of them. 或者,您可能有800个。 Both are valid representations of the data inside the database. 两者都是数据库内部数据的有效表示形式。

So, what you want to do does not make sense given how data is structured in a database. 因此,鉴于数据库中数据的结构方式,您要执行的操作没有任何意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM