After the tinyint server determines the number, it displays the corresponding content. varchar directly stores the content to be displayed. For example, it stores the XXX category. For example, it stores the corresponding content after the tinyint server determines the number.
Varchar directly stores the content to be displayed.
Such as the classification of stored XXX
Such as male/female
(Answers for beginners)
Reply content:
The tinyint server determines the number and then displays the corresponding content.
Varchar directly stores the content to be displayed.
Such as the classification of stored XXX
Such as male/female
(Answers for beginners)
According to the "rules", the database design should conform to three paradigms, that is, to create a special table to store the "category ". However, in actual situations, it would be better to directly store the "content to be displayed" if the "category is basically not changed", so that you do not need to query another table when getting data, reduce one query. Of course, the disadvantage is that the occupied space is too large, but it is wise to take the space for time.
For PHP, there are numbers in the database. It is also a good practice to get the "category" name through an array when getting the numbers.
In addition, when the number of categories is only a few, for example, "male and female", it is also common to directly specify 1 as male and 0 as female, but remember to add comments/descriptions to the field.
Finally, a small detail is provided. strings with fixed lengths are stored in char and stored in varchar, which is faster in reading.
Use enum
We recommend that you use enum in MySQL,
It represents the string form of varchar,
But actually only occupies one tinyint (maybe, I'm not sure. I remember that enum seems to occupy 2 bytes of space.
Char, which cannot be converted.