在设计数据库时,存储多个true/false值的首选方法是什么? [英] When designing databases, what is the preferred way to store multiple true / false values?

查看:48
本文介绍了在设计数据库时,存储多个true/false值的首选方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如标题中所述,在设计数据库时,处理具有多列的表的首选方法是,这些表仅将true/false值存储为一个或一个值(例如"Y/N:或"0" /1)?同样,在不同的数据库(例如Oracle和SQL Server)之间是否会出现一些问题,可能会影响列的处理方式?

As stated in the title, when designing databases, what is the preferred way to handle tables that have multiple columns that are just storing true / false values as just a single either or value (e.g. "Y/N: or "0/1")? Likewise, are there some issues that might arise between different databases (e.g. Oracle and SQL Server) that might affect how the columns are handled?

推荐答案

SQL Server中,存在BIT数据类型.您可以在那里存储0或1,比较这些值,但不能运行MINMAX.

In SQL Server, there is BIT datatype. You can store 0 or 1 there, compare the values but not run MIN or MAX.

Oracle中,您只需使用NUMBERCHAR(1).

MySQLPostgreSQL中,任何数据类型都可以隐式转换为BOOLEAN.

In MySQL and PostgreSQL any datatype is implicitly convertible to BOOLEAN.

两个系统都支持BOOLEAN数据类型,您可以在WHEREON子句中直接使用BOOLEAN数据类型:

Both systems support BOOLEAN datatype which you can use as is, without the operators, in the WHERE or ON clauses:

SELECT  *
FROM    mytable
WHERE   col1

,这在SQL ServerOracle中是不可能的(您需要在其中具有某种种类或谓词).

, which is impossible in SQL Server and Oracle (you need to have some kind or a predicate there).

MySQL中,BOOLEANTINYINT(1)的同义词.

PostgreSQL中(在存储方面),但从逻辑上讲,它不能隐式转换为任何其他类型.

In PostgreSQL too (in terms of storage), but logically, it's not implicitly convertible to any other type.

这篇关于在设计数据库时,存储多个true/false值的首选方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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