Best data type for storing a single digit?

I need a data type to store this range: [0 - 9]. Something like that:

+-----+
| col |
+-----+
| 3   |
| 2   |
| 8   |
| 0   |
| 2   |
| 1   |
+-----+

What data type is best in this case?

+4
source share
3 answers

Despite the documentation, I don’t understand whether the size is DECIMAL(1,0)“rounded” to four bytes or whether one digit is considered a “left digit”, which results in a single byte width for the entire data type.

, , TINYINT, a TINYINT - , - ( , !).

, TINYINT. - .

, , ENUM s, , , . 255 , TINYINT, .

ENUM('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')

, . .

+6

You can use int, bigint, smallint and tinyint depending on the requirement.

https://msdn.microsoft.com/en-us/library/ms187745.aspx

Perhaps you can store the values ​​in an enumeration and use the same class.

@Shafizadeh I'm new here, and I mentioned that I used the listing first among all the answers, but my answer was roughly marked.

-1
source

Source: https://habr.com/ru/post/1622835/


All Articles