gpt4 book ai didi

sql-server - 为空值存储位列?

转载 作者:行者123 更新时间:2023-12-04 02:25:43 25 4
gpt4 key购买 nike

Microsoft 文档位于 https://docs.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-2017说:

An integer data type that can take a value of 1, 0, or NULL.

The SQL Server Database Engine optimizes storage of bit columns. If there are 8 or fewer bit columns in a table, the columns are stored as 1 byte. If there are from 9 up to 16 bit columns, the columns are stored as 2 bytes, and so on.The string values TRUE and FALSE can be converted to bit values: TRUE is converted to 1 and FALSE is converted to 0.Converting to bit promotes any nonzero value to 1.


如何在一位中存储 1、0 和 NULL?

最佳答案

引用@MarkByers 在问题 How much size “Null” value takes in SQL Server 中的规范答案关于 SQL Server 如何存储 NULL一般来说:

In addition to the space required to store a null value there is also an overhead for having a nullable column. For each row one bit is used per nullable column to mark whether the value for that column is null or not. This is true whether the column is fixed or variable length.



所以,我希望 BIT type 的行为与任何其他列相同,这意味着将有一个单独的位来跟踪该列是否为 NULL与否 NULL .因此, BIT SQL Server 中的 column 实际上使用两位来跟踪这三个值。

关于sql-server - 为空值存储位列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53513422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com