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
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
