mohaidar
mohaidar

Reputation: 4276

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?

Upvotes: 1

Views: 2131

Answers (1)

John Bell
John Bell

Reputation: 2350

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.

Upvotes: 3

Related Questions