sqlsql-serverintegersqldatatypestinyint

SQL: Is it efficient to use tinyint instead of Integer if my max value is 255?


Lets assume I want to save the count of datagrid rows which can be max. 24 because each row is 1 hour.

To save the row index in the database a tinyint field would be totally enough. But back in my mind I remember slightly that databases are optimized for integers?!

So is it worth to use tinyint?


Solution

  • With a narrower table, the database will fit more records in a single IO page, and will therefore require fewer hard disk reads.

    The rule of thumb is to always use the data type that will require the least storage size.