Reputation: 3790
Nice simple question for the db guys, Its not terribly important but im curious.
Is there something smaller (numeric) that is smaller than a tinyint
.
Im storing 120 different values and nearly all of them are going to be (0-9)
.
A tinyint
is the smallest I can find and it hold a value of upto 255
. (3 digits)
Im using MSSqlServer 2008 version 10.00.1600
Upvotes: 2
Views: 930
Reputation: 1353
You can of course manually pack multiple of your elements into one field; since almost every computing system is byte (8-bit) oriented, typically the smallest usefully available element is just one byte, 8 bits, that can represent 0-255 (or -128 to 127) for example.
Upvotes: 1
Reputation: 37194
Numerically tinyint
is likely as small as you can go (it really depends on the database engine you are using). You could use char(1)
and then rely on implicit conversion to query the values but that would be needless overhead to solve a problem that doesn't really need solving. Also, char(1)
is still going to consume 1 byte, 8 bits, which ranges 0-255. I would consider this a micro-optimization and not worth the time/effort.
I know you are probably asking for academic purposes, but in terms of database storage, tinyint
is small enough for almost all situations. If you are that concerned about space consumption, I would say you need to look at other options than a traditional RDBMS.
Upvotes: 3