True/False vs 0/1 in MySQL(真/假与 MySQL 中的 0/1)
问题描述
在 MySQL 数据库中哪个更快?布尔值,还是使用零和一来表示布尔值?我的前端只有一个是/否单选按钮.
Which is faster in a MySQL database? Booleans, or using zero and one to represent boolean values? My frontend just has a yes/no radio button.
推荐答案
某些前端"在启用使用布尔值"选项的情况下,会将所有 TINYINT(1) 列视为布尔值,反之亦然.
Some "front ends", with the "Use Booleans" option enabled, will treat all TINYINT(1) columns as Boolean, and vice versa.
这允许您在应用程序中使用 TRUE 和 FALSE 而不是 1 和 0.
This allows you to, in the application, use TRUE and FALSE rather than 1 and 0.
这根本不会影响数据库,因为它是在应用程序中实现的.
This doesn't affect the database at all, since it's implemented in the application.
在 MySQL 中并没有真正的 BOOLEAN 类型.BOOLEAN 只是 TINYINT(1) 的同义词,TRUE 和 FALSE 是 1 和 0 的同义词.
There is not really a BOOLEAN type in MySQL. BOOLEAN is just a synonym for TINYINT(1), and TRUE and FALSE are synonyms for 1 and 0.
如果在编译器中完成转换,应用程序的性能不会有任何差异.否则,差异仍然不会很明显.
If the conversion is done in the compiler, there will be no difference in performance in the application. Otherwise, the difference still won't be noticeable.
您应该使用可以让您更有效地编码的任何方法,尽管不使用该功能可能会减少对特定前端"供应商的依赖.
You should use whichever method allows you to code more efficiently, though not using the feature may reduce dependency on that particular "front end" vendor.
这篇关于真/假与 MySQL 中的 0/1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:真/假与 MySQL 中的 0/1
基础教程推荐
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
