What is the best data type to store boolean values in a database

こ雲淡風輕ζ 提交于 2019-12-23 21:15:26

问题


What is the best data type to store boolean values in a database? which is supported by mostly used RDBMS types such as Mysql,oracle,postgres,mssql


回答1:


you can use TINYINT or bit datatype




回答2:


If the DBMS supports a real boolean type (e.g. PostgreSQL) then use that. If it doesn't I usually prefer an integer value combined with a check constraint that ensures that only 0 and 1 can be stored. In my experience it also makes sense to define the column as NOT NULL as well. Having a NULL value for a boolean is always somewhat confusing.

You won't find a single datatype that works for all DBMS. I would always use the "best" one that the DBMS offers.



来源:https://stackoverflow.com/questions/18872023/what-is-the-best-data-type-to-store-boolean-values-in-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!