is it practical to use bit data type to store true/false into sql database?
is it practical to use bit data type to store true/false value into sql database? I read that some people use tinyint(1) but I do not know why?, is it different in performance and more practical? is their any problem at the time of conversion to Boolean type?
By practical I assume you mean an advantage over using another method to store boolean values. SQL Server implicitly converts boolean values to bit
type, so amongst the other benefits (largely being that using the bit
type is stored as 1 byte, extremely efficient), it makes sense to use it since you're making less work for yourself, no need for defaults or constraints. tinyint
however (also stored as 1 byte), can store values up to 255 naturally, and you will likely experience conversion errors when trying to implicitly convert boolean values from an application layer.
TL;DR Always use an appropriate type. bit
type is appropriate for boolean values, therefore there's no reason not to use it.
上一篇: 如何在MySQL中存储布尔数据类型?