Search code examples
sqldatabasecreate-table

Boolean datatype in SQL causing issues?


If I wanted to use a datatype that acts like a boolean/binary/gives me Y/N, what datatype would I use?

I basically need YesNo to store any kind of boolean/binary/Y/N value.

This is what I have so far, however, isn't working.

CREATE TABLE TEST(
    TestID int(3) PRIMARY KEY,
    YesNo boolean
);

INSERT INTO TEST(TestID, YesNo) VALUES ('999', TRUE);

Solution

  • I don't think databases have a Boolean type. An alternative to this would be using a BIT instead. Then set this BIT value to either a 1 or 0. Also, It is standard practice for 0 to be construed as FALSE, 1 to be construed as TRUE and Nulls, when allowed, would be reflected as NULL.