Signed Integer Ranges: Why and How

Whether you are working in T-SQL, Oracle, MySQL, C#, or Java, the range of possible values for a signed (positive or negative) 32-bit integer is from $latex -2^{31}$ or (-2,147,483,648) to $latex (2^{31})-1$ or (2,147,483,647). The fact that it's so consistent across so many different platforms (and also against plenty of others I didn't list) means there has to be more to it than just the preference of some developers somewhere, right? Exactly right. Down to the bits Any data your computer deals with, be it numbers, text, music or videos, all end up in binary at one point or another. Binary means…
Read More

Three-Byte Integers in SQL Server: Fact or Fiction?

I've been told on two occasions that the absence of the MEDIUMINT datatype is a serious shortcoming of SQL Server. If you're not familiar with MEDIUMINT, it's an integer type available in MySQL that consumes 3 Bytes and is capable of storing values ranging from -8,388,608 to 8,388,607 (signed) or from 0 to 15,777,215 (unsigned). While SQL Server has many datatypes, it has nothing that exactly matches MEDIUMINT. In SQL Server, if you wanted to store a value between 32,768 and 2,147,483,647 you would need to use the INT datatype, each of which takes up 4 Bytes. The next smallest…
Read More