Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create a yes/no boolean field in SQL server?

What is the best practice for creating a yes/no i.e. Boolean field when converting from an access database or in general?

like image 228
leora Avatar asked Nov 22 '09 00:11

leora


People also ask

How do you create a boolean field in SQL Server?

In SQL Server, a Boolean Datatype can be created by means of keeping BIT datatype. Though it is a numeric datatype, it can accept either 0 or 1 or NULL values only. Hence easily we can assign FALSE values to 0 and TRUE values to 1. This will provide the boolean nature for a data type.

How do you set a Boolean value in SQL query?

You can update boolean value using UPDATE command. If you use the BOOLEAN data type, MySQL internally convert it into tinyint(1). It can takes true or false literal in which true indicates 1 to tinyint(1) and false indicates 0 to tinyint(1).

Is there a Boolean data type in SQL Server?

There is boolean data type in SQL Server. Its values can be TRUE , FALSE or UNKNOWN . However, the boolean data type is only the result of a boolean expression containing some combination of comparison operators (e.g. = , <> , < , >= ) or logical operators (e.g. AND , OR , IN , EXISTS ).


2 Answers

The equivalent is a BIT field.

In SQL you use 0 and 1 to set a bit field (just as a yes/no field in Access). In Management Studio it displays as a false/true value (at least in recent versions).

When accessing the database through ASP.NET it will expose the field as a boolean value.

like image 98
Guffa Avatar answered Sep 24 '22 02:09

Guffa


The BIT datatype is generally used to store boolean values (0 for false, 1 for true).

like image 37
Alex Martelli Avatar answered Sep 26 '22 02:09

Alex Martelli