How to store unsigned 64-bit integers in SQL Server?

I am working with an application that uses quite large numbers, and I need to store the data as an unsigned 64-bit integer. I prefer to just store it, without worrying about manipulating bits or something like that, so different programs can use the data in different ways.

+7
sql-server unsigned
source share
2 answers

You can save the value in type NUMERIC with a scale of 0, which preserves the semantics of integer . The NUMERIC type will give negative numbers, although you can set a constraint that requires positive integers.

The maximum precision for NUMERIC is 38 decimal digits. 2**64 is somewhere around 18 or 19 decimal digits, so NUMERIC(19,0) is likely to work fine for this data.

+5
source share

AFAIK, you will need to create your own type. Pointers are here , although this article is more intended to limit negative numbers ...

+2
source share

All Articles