数据库中的空值使用的空间 [英] Space used by nulls in database

查看:141
本文介绍了数据库中的空值使用的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果列为null,是否影响列使用的空间?
是否使用由列定义固定的空间?
这从数据库到数据库有所不同。
(我主要感兴趣的是SQL Server 2000.)

If a column is null, does that affect the space used by the column? Is the space used fixed by the column definition? Does this vary from database to database. (I am mainly interestred in SQL Server 2000.)

澄清:
这个问题不是当列是'nullable' (这一成本再次降低,Kritsen&gbn指出)。问题是,当列实际上为null(在某个特定的行)时是否有任何保存。

Clarification: The question relates not to what happens when the column is 'nullable' (This costs another bit as Kritsen & gbn pointed out). The question is, is there any saving when the column is actually null (in some particular row).

...

Cadaeic为SQL Server提供了答案,似乎在SQL Server中没有节省,直到版本2008,而根据Quassnoi,如果空列在结尾,您可以在Oracle中获得节省。感谢您的答案,他们都是有帮助的。

Cadaeic provided the answer for SQL Server which seems to be no savings in SQL Server until version 2008, whereas according to Quassnoi you can get savings in Oracle if the null columns are at the end. Thanks for the answers, they were all helpful.

推荐答案

在列中存储NULL不会特别成本或节省空间。对于固定长度数据,整个空间仍然保留。

Storing a NULL in a column does not specifically cost or save space. For fixed-length data, the entire space is still reserved.

另一方面,可变长度数据只需要数据的长度加开销来存储实际长度。例如,VARCHAR(n)将使用2字节的数据来表示实际长度,因此所需的存储空间总是n + 2。

On the other hand, variable-length data requires only the length of the data plus overhead to store the actual length. For example, a VARCHAR(n) will use 2 bytes of data to indicate that actual length, so the storage space required is always n+2.

如果SET ANSI_PADDING ON,具有NULL值的char(n)将表现为VARCHAR(n)。

Additionally, it should be mentioned that if SET ANSI_PADDING ON, a char(n) with a NULL value will behave as a VARCHAR(n).

无论如何,当使用SQL Server 2000或SQL Server 2005时,节省存储NULL。SQL Server 2008引入了一个稀疏列的概念,这可以为主要为NULL的列节省。

No matter what, you will not recognize space "savings" from storing NULLs when using SQL Server 2000 or SQL Server 2005. SQL Server 2008 introduces the concept of a sparse column, which can yield savings for columns that are primarily NULL.

这篇关于数据库中的空值使用的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆