Column gender: male, female.
In general, flags (columns with да/нет
values) are, of course, more convenient to store in boolean
(1/0).
But specifically the column "gender" I would have stored in char(1)
. Especially if the field is required. The system resources char(1)
will not eat much more than a boolean
, but purely organizationally for any kind of reports is easier: М/Ж
displayed, not 1/0
, which are then somehow translated into the same М/Ж
still need ...
Once again: this is only specifically for the column "floor".
Column your education: Economist, Psychologist, Lawyer.
Column product categories: Chairs, Tables, Wardrobes, Beds, Sofas.
Here I agree with the option number 1 from @Suvitruf: use directories. Separate reference tables with variants of values, and in the main table to store only id
from the corresponding reference book.
There are many advantages:
- editing: if the value changes, you change it only in one place
- organization: if the order of these values between themselves is important, then it is possible (necessary) to store the sequence number in the queue in this directory
- organization (2): if there are any attributes inherent in each value - you can also store it in the same reference table without touching the main one
- multilingual: if your project is in several languages, then you keep all the options in the directory, and adding another language will not be a problem for you
Still.
If you have several fields for which reference tables can be used, and the options in these directories will be only text without any attributes (see paragraphs 1-3 of the list above), then you can organize one table- reference to several columns.
Those. A table of this type is created:
id [int] PK attribute [enum(education, category)] value varchar(32)
It contains all the data:
id| attribute | value ---------------------- 1 | education | Экономист 2 | education | Психолог 3 | education | Юрист 4 | category | Стулья 5 | category | Столы 6 | category | Шкафы 7 | category | Кровати 8 | category | Диваны
And already id
this one table are brought in the main.
Strictly speaking, even here you can organize the sequence (point 2 of the list above), but these are details.
UPDATE
- What stores do you visit most often: Supermarket, Megamarket, Hypermarket, regular store, kiosk, market.
- How tall are you: low, medium, high, huge
- What is your clothing size: M, S, L, XL, XXL, XXXL
In the examples above, I do not see the point in making reference books.
Well, if you have a fixed set of values, and this set will not change, then I think it is easier to store in enum
.
Moreover, enum
takes 1 or 2 bytes (depending on the number of values), and int
- as much as 4 bytes :)
In general, my answer: enum