19

Is there a 4 byte unsigned int data type in MS SQL Server?

Am I forced to use a bigint?

4 Answers 4

15

Can you just add/subtract 2,147,483,648 (2^31) to the regular int ? (subtract on the way in, & add coming out) I know it sounds silly, but if you declare a custom datatype that does this, it's integer arithmetic and very fast.... It just won't be readable directly from the table

Sign up to request clarification or add additional context in comments.

3 Comments

Would there be a potential for overflow?
No, your application values from 0 to 2^32 - 1 would map to the database values of - 2^31 - + 2^31 - 1
Before google analytics came out, there were a lot more companies making web statistics tracking software. I remember that this is the way a lot of them stored IP addresses without going to bigint...
9

It doesn't seem so.

Here's an article describing how to create your own rules restricting an int to positive values. But that doesn't grant you positive values above 2^31-1.

http://www.julian-kuiters.id.au/article.php/sqlserver2005-unsigned-integer

Comments

0

You can use bigint with checked the constraint, but datatype will still in 8 byte :(

1 Comment

that's why this is not a viable solution at all
-3

I used BINT(11) instead of INT(11), and it acts as UNSIGNED INT(11)

1 Comment

I'm pretty sure that's not a valid answer for SQL Server. The question was asked with the sql-server-2005 tag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.