I store at tinyint (1) - 0 or 1 . I check:
WHERE is_public='1'
Of course, everything works, but I feel that this is wrong. The question is how to organize it correctly and more beautifully?
I store at tinyint (1) - 0 or 1 . I check:
WHERE is_public='1'
Of course, everything works, but I feel that this is wrong. The question is how to organize it correctly and more beautifully?
These values are often stored in CHAR(1)
as 'Y' and 'N'. From the advantages of this approach can be noted visibility. However, there is no savings compared with TINYINT(1)
, moreover, if at least one VARCHAR
column is used in the table, all CHAR columns are automatically treated as VARCHAR
. VARCAHR columns are placed in a separate area and are processed more slowly than TINYINT
, secondly one byte will be used to set the size of the VARCHAR value and two will be used instead of one byte. Therefore, TINYINT(1)
is the most economical and correct option. It is often used by well-known frameworks, for example, Ruby on Rails. I would not change anything in your place.
Source: https://ru.stackoverflow.com/questions/510778/
All Articles