Which is the smallest datatype to store an integer value in SQL Server 2008?
I am creating a small database application. I want to store the count of an item in a database table which will never cross value more than one hundred.
What is the most suitable datatype for this field? I am using this field for s开发者_开发知识库ome calculation also.
use tinyint - one byte of storage space
While you can use TinyInt, are you sure it will never be more than a hundred? I'd be careful about trying to optimize TOO much. Maybe it's something like a rating where ratings are always between 0 and 100, but if it's something that could potentially go over that at some point in the future, I might just go with a traditional Int. Maybe you need all the memory you can get so you need to really watch what values you use but this isn't too common.
I guess what I'm trying to say is don't get too aggressive about optimization of something that will generally not make much difference at all.
Tinyint
. Allows you to store values from 0 to 255.
精彩评论