3

What is the best data type to store boolean values in a database? which is supported by mostly used RDBMS types such as Mysql,oracle,postgres,mssql

2 Answers 2

4

you can use TINYINT or bit datatype

Sign up to request clarification or add additional context in comments.

1 Comment

thanks I;l be using TINYINT as it is supported by many data storages
2

If the DBMS supports a real boolean type (e.g. PostgreSQL) then use that. If it doesn't I usually prefer an integer value combined with a check constraint that ensures that only 0 and 1 can be stored. In my experience it also makes sense to define the column as NOT NULL as well. Having a NULL value for a boolean is always somewhat confusing.

You won't find a single datatype that works for all DBMS. I would always use the "best" one that the DBMS offers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.