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?
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.
The BIT
datatype is generally used to store boolean
values (0
for false
, 1
for true
).
You can use the bit
column type.
You can use the BIT
field.
For adding a BIT column to an existing table, the SQL command would look like:
ALTER TABLE table_name ADD yes_no BIT
If you want to create a new table, you could do: CREATE TABLE table_name (yes_no BIT)
.