I have three values: 0
, 1
, NULL
. Now I want to know, what data type is fine for that column?
我有三个值:0,1,NULL。现在我想知道,该列可以使用哪种数据类型?
But the way, NULL
is default of that column (in the database) and I achieve 0
and 1
form parameter (get method) of URL. Something like this:
但是方式,NULL是该列的默认值(在数据库中),我实现了URL的0和1表单参数(get方法)。像这样的东西:
www.example.com/?q=param=0
And then
接着
$var = isset($_GET['param']) ? $_GET['param'] : null;
And then
接着
INSERT INTO table(col) values ($var);
8
TINYINT(1) UNSIGNED NULL
tinyint's are perfect for booleans
tinyint非常适合布尔人
11
I would use Bit-Value Type - BIT
我会使用比特值类型 - BIT
BIT(1) NULL DEFAULT NULL
BIT(1)
needs 1 Byte of storage, wich is the same as TINYINT(1)
does. The difference is that BIT(1)
only accepts the values 0
and 1
(or b'0'
and b'1'
) while TINYINT(1) UNSIGNED
accepts values from 0
up to 255
. The length defined in the brackets for TINYINT
does not take any affect to values that can be stored. It is only an information for clients, how to display the values (e.g. if you use ZEROFILL
).
BIT(1)需要1个字节的存储空间,与TINYINT(1)相同。不同之处在于BIT(1)只接受值0和1(或b'0'和b'1'),而TINYINT(1)UNSIGNED接受0到255之间的值.TINYINT括号中定义的长度确实如此不会对可以存储的值产生任何影响。它只是客户的信息,如何显示值(例如,如果您使用ZEROFILL)。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2015/12/25/239fd9b0795224bff214207b6c83c5ea.html。