Reputation: 465
I have created one table and I want to store numbers from 1 to 60 numbers only inside the field.
What should I put in the datatype of the table field? Should I use TINYINT (4)
datatype?
Upvotes: 2
Views: 1371
Reputation: 1269633
"Best" data type is open to interpretation. Here are three options:
numeric(2, 0)
varchar(2)
tinyint(2)
These have different sizes, but that doesn't make them "best" -- except under certain circumstances where storage space is a primary concern. I am guessing that your "numbers" are not really numbers, but are codes of some sort that vary from 1 to 60.
If these are referencing a reference table, then tinyint
makes sense as the key, because keys are often numbers. However, I often use int
for such keys. The extra three bytes usually have little impact on performance.
If the code is zero-padded (so '01'
rather than '1'
), then char(2)
is the appropriate type. It might take more space, but it accurately represents the value.
If these are indeed numbers -- like addition or multiplication is defined -- then tinyint
is definitely the most appropriate type.
Upvotes: 2
Reputation: 602
Yes TINYINT
is the best option its from -128 to 127!
Documentation Link: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
Upvotes: 0