Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't SQL Server support unsigned datatype?

I am specifically thinking about unsigned int.

Here is a practical example: what do you do when your identity column maxes out? It's possible to either go BigInt (8 bytes storage instead of 4) or to refactor the application to support negative integers, and even to create your own rules as indicated in this answer; neither of those options are optimal.

UInt would be an ideal solution, but SQL Server does not offer it (where MySQL does).

I understand that unsigned datatypes are not part of the SQL standard (SQL-2003) but still seems like a waste to me.

What is the reason of not including these (in SQL Server or in the standard)?

like image 625
Romhein Avatar asked Dec 15 '10 15:12

Romhein


People also ask

Does SQL Server support unsigned INT?

SQL Server doesn't support unsigned integers.

What is unsigned data type in SQL?

The “unsigned” in MySQL is a data type. Whenever we write an unsigned to any column that means you cannot insert negative numbers. Suppose, for a very large number you can use unsigned type. The maximum range with unsigned int is 4294967295. Note: If you insert negative value you will get a MySQL error.

When would it make sense to use an unsigned data type?

When would it make sense to use an unsigned data type? When all possible values are positive numbers. Which of the following SQL Server data types would probably be the best choice for a field containing data on each student's score (out of 100) on a mid-term?

Does Postgres support unsigned?

PostgreSQL doesn't support the UNSIGNED attribute, but it an be enforced by using the CHECK constraint. Otherwise, negative values could be inserted in pgsql databases.


2 Answers

If I had to guess, I would say that they are trying to avoid a proliferation of types. Generally speaking there isn't anything that an unsigned integer can do that a signed integer can't do. As for the case when you need a number between 2147483648 and 4294967296 you probably should go to an 8 byte integer since the number will also eventually exceed 4294967296.

like image 80
Jeff Hornby Avatar answered Sep 21 '22 05:09

Jeff Hornby


For that purpose you could use -2,147,483,648 as the seed value.

Identity(-2147483648, 1) 
like image 35
CFreitas Avatar answered Sep 19 '22 05:09

CFreitas