问题描述
检索 bit 或 char(1) 是否有任何性能差异?
Is there any performance difference on retrieving a bit or a char(1) ?
出于好奇=]
更新:假设我使用的是 SQL Server 2008!
UPDATE: Suposing i'm using SQL Server 2008!
推荐答案
对于 SQL Server:一个字节内最多可以存储 8 列 BIT
类型的列,而 类型的每一列>CHAR(1)
将占用一个字节.
For SQL Server: up to 8 columns of type BIT
can be stored inside a single byte, while each column of type CHAR(1)
will take up one byte.
另一方面:BIT
列可以有两个值(0 = false,1 = true)或根本没有值 (NULL) - 而 CHAR(1)
可以有任何字符值(更多的可能性)
On the other hand: a BIT
column can have two values (0 = false, 1 = true) or no value at all (NULL) - while a CHAR(1)
can have any character value (much more possibilities)
实际上,归结为:
- 您真的需要真/假(是/否)字段吗?如果是这样:使用
BIT
- 您是否需要具有两个以上可能值的东西 - 使用
CHAR(1)
从性能的角度来看,我认为这没有任何显着差异 - 除非您有数万列.那么当然,使用 BIT
可以在单个字节中存储多达 8 列将是有益的.但同样:对于您的普通"数据库案例,您有几列,一打这样的列,这真的没有太大区别.选择适合您需求的列类型 - 不要过度担心性能.....
I don't think it makes any significant difference, from a performance point of view - unless you have tens of thousands of columns. Then of course, using BIT
which can store up to 8 columns in a single byte would be beneficial. But again: for your "normal" database case, where you have a few, a dozen of those columns, it really doesn't make a big difference. Pick the column type that suits your needs - don't over-worry about performance.....
这篇关于SQL:Bit 或 char(1) 哪个更好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!