Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Boolean Values In SQL?

Tags:

c#

sql

I'm designing a SQL datbase table and a couple of the columns need to hold either a 1 or 0 (true or false). I define the columns to be of type binary(1), but now I don't know how to insert a true or false value into the database. inserting "true" or "1" doesn't work (it says either int or bool cannot be converted to binary)...

like image 545
sooprise Avatar asked Sep 14 '10 13:09

sooprise


2 Answers

Use bit

This accepts the strings "true" and "false".

It also maps directly to the c# boolean type which is useful

like image 96
gbn Avatar answered Oct 21 '22 11:10

gbn


Use the bit data type instead for your column. Then you can insert true/false directly.

like image 32
Klaus Byskov Pedersen Avatar answered Oct 21 '22 09:10

Klaus Byskov Pedersen