Consider a table whose job is to store a rating of an object. The column of interest here is the one called RATING. The valid range of values to store is:
- 1
- 0
- -1
The first thought was to store as a tinyint smallint. This would store only one byte two bytes per row. Given the tinyint’s range of 0 to 255 smallint’s range of -32768 to 32767, would it be suitable here? Is there another datatype more suitable? The space taken is trivial for the expected size of the table & database. The user interface will be responsible for ensuring that those three values will be chosen by way of an enum.
Question: can you suggest a smaller storage size or any clever setups to store one of these three values without sacrificing any ease-of-understanding?
Other considerations:
- storage space isn’t a terribly large concern
- this value will be summed to get a total rating
- this may be a case of micro-optimization
- SQL Server 2008
smallint is the (ahem) smallest integer datatype that can accurately track -1, 0, and 1. If space is not an issue, and you have said that it isn’t, then use smallint. Anything else would be overly clever and would require far more implementation work than is necessary.