可以在Microsoft存储三个值字段中的单个位? [英] Can Microsoft store three-valued fields in a single bit?

查看:103
本文介绍了可以在Microsoft存储三个值字段中的单个位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全懵SQL /数据库,但我有一个朋友谁做了一些数据库如何使用布尔字段很多数据库的工作,可以采取NULL值除了真假聊天

I'm completely ignorant of SQL/databases, but I was chatting with a friend who does a lot of database work about how some databases use a "boolean" field that can take a value of NULL in addition to true and false.

对此,他做沿着这些路线评论:微软的功劳,他们从来没有提到这一领域的一种作为一个布尔值,他们只是把它一下,它是一个真正有点 - 如果你有八。在创纪录的少位字段,只需要一个字节来存储他们全部。

Regarding this, he made a comment along these lines: "To Microsoft's credit, they have never referred to that kind of field as a boolean, they just call it a bit. And it's a true bit - if you have eight or fewer bit fields in a record, it only requires one byte to store them all."

当然,这似乎是不可能的,我 - 如果字段可以容纳三个值你不会适合他们的八进一个字节。我的朋友认为,这似乎有点奇怪,但求低层内部的无知和说,到目前为止,他所知,从SQL侧面观察这些领域可以容纳三个值,它并制定出需要一个存储字节。我想我们中的一个已经越过线。谁能解释一下什么是真正回事?

Naturally that seems impossible to me - if the field can hold three values you're not going to fit eight of them into a byte. My friend agreed that it seemed odd, but begged ignorance of the low-level internals and said that so far as he knew, such fields can hold three values when viewed from the SQL side, and it does work out to require a byte of storage. I imagine one of us has a wire crossed. Can anyone explain what's really going on here?

推荐答案

我建议你读这为null存储的一个很好的解释:<一href=\"http://weblogs.sqlteam.com/mladenp/archive/2007/09/06/How_does_SQL_Server_really_store_NULL-s.aspx\">How它的SQL Server存储真正NULL-S 。总之,空/非空位被存储在不同的地方,对于该行的空位图。

I recommend reading this for a good explanation of null storage: How does SQL Server really store NULL-s. In short, the null/not null bit is stored in a different place, the null bitmap for the row.

从文章:

每一行都有为允许空值列空的位图。如果该列的行为null,则位图中位为1否则它就是0。

Each row has a null bitmap for columns that allow nulls. If the row in that column is null then a bit in the bitmap is 1 else it's 0.

因此​​,虽然实际的的8位列存储在1个字节,出现在该行的零位的额外位指出,如果该列是NULL或不...所以取决于如何你计数。是的完全的准确,8 bit列使用 2字节,刚分手2个不同的位置。

So while the actual values for 8 bit columns are stored in 1 byte, there are extra bits in the row's null bitmap that indicate if that column is NULL or not...so depends on how you're counting. To be completely accurate, 8 bit columns use 2 bytes, just split up in 2 different locations.

这篇关于可以在Microsoft存储三个值字段中的单个位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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