Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL: Smallest datatype for one bit

I would like to add a column to the table which contains either of two values: 1 or 0.

What would be the smallest datatype to store the data in MySQL?

A TINYINT(1) can contain numbers between -127 to 127.

like image 736
Michiel Pater Avatar asked Feb 11 '11 11:02

Michiel Pater


Video Answer


1 Answers

You can use bit(1)

http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html

BOOL is stored in MySQL as TINYINT which would take 1 full byte

http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html

A bit(1) would normally also take 1-byte but if there are multiple bits in a single record, then they get stored in the same byte, up to 8 per byte.

like image 91
RichardTheKiwi Avatar answered Oct 21 '22 13:10

RichardTheKiwi