I have mysql table for car's accessories like "airconditioner, park assist, cd player, brake assist" and etc. All of them are in INT(11)
. But I am using them like 1
, if the car has this one, or NULL
, if it hasn't. Should I change this INT(11)
with something other? If I can, please tell me how?
Asked
Active
Viewed 44 times
0
-
1Use boolean, which is `tinyint(1)`. Then you can use 1/0 instead. – aynber Jun 08 '18 at 13:38
-
2Please post your table structure. There may or may not be something wrong with what you are doing. – Tim Biegeleisen Jun 08 '18 at 13:46
-
That `11` doesn't mean number of stored digits. Anyway, you may want to take look at `char(1)`. – revo Jun 08 '18 at 13:50
-
1I hope these aren't individual columns :-( – Strawberry Jun 08 '18 at 14:39
2 Answers
1
You'll save a little disk space on your database server by making this change. You don't need to change your application logic at all; both TINYINT
and INT
are integers you can compare to 1 or 0.
Note that MySQL ignores the 11
in INT(11)
and the 1
in TINYINT(1)
. INT
values are 32-bit numbers, and TINYINT
values are 8-bit numbers.
Unless you have millions of rows in the table, making this change will probably save you only a tiny amount of space. It's already cost you more in your time to ask this question than it will save over a decade of running this database.

O. Jones
- 103,626
- 17
- 118
- 172
0
What you're doing is creating flags to indicate yes or no values, so that is more suitable for a boolean data type, you can learn how to use boolean values in MySQL from this post.

Royal Wares
- 1,192
- 10
- 23
-
I changed it to tinyint(1), because my code is AirConditioner==1) {?> Am I right? – Gntr Jun 08 '18 at 13:54
-