Everyone has their own ideas. I prefer to use tinyint, which only occupies one byte. Using enum is inflexible. For example, if 1 is defined as male and 2 is female, if I want to display 1 as male, 2 is a woman, so it is inconvenient.
On MYSQL, it is not recommended to use NULL. NULL takes up four characters and records too much. This is unnecessary loss. When querying, use where field is null or field is not null, like this The query is not very efficient. Set the field to default '', so that it can be where field = '' or field != '', or it is not allowed to be empty NOT NULL.
I am a half-experienced DBA. I may not know which book I read this in. Our company’s DBA does not allow fields to be NULL, and there are even more bizarre ones.
This is just like when goto was not allowed to be used in C language programming, a half-baked “expert”
type Using 1,2 is not a good design in itself. Over time, you always need to look at the code to understand the meaning. It's much better to use enum types and give each type an appropriate name.
But if this field requires related queries, it is not recommended to use it, as the performance will be severely degraded.
Everyone has their own ideas. I prefer to use
tinyint
, which only occupies one byte. Usingenum
is inflexible. For example, if 1 is defined as male and 2 is female, if I want to display 1 as male, 2 is a woman, so it is inconvenient.On MYSQL, it is not recommended to use
NULL
.NULL
takes up four characters and records too much. This is unnecessary loss. When querying, usewhere field is null
orfield is not null
, like this The query is not very efficient. Set the field todefault ''
, so that it can bewhere field = '' or field != ''
, or it is not allowed to be emptyNOT NULL
.I am a half-experienced DBA. I may not know which book I read this in. Our company’s DBA does not allow fields to be NULL, and there are even more bizarre ones.
This is just like when goto was not allowed to be used in C language programming, a half-baked “expert”
type
Using 1,2 is not a good design in itself. Over time, you always need to look at the code to understand the meaning. It's much better to useenum
types and give each type an appropriate name.But if this field requires related queries, it is not recommended to use it, as the performance will be severely degraded.
When connecting Java to MySQL, I don’t recognize tinyint, only 0 and 1
It makes sense to use tinyint. Don't listen to the DBA nonsense.