Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you store unsigned 64-bit integers in SQL Server?

I work with an application which uses rather big numbers and I need to store data as an unsigned 64-bit integer. I prefer to just store it without worrying about bit manipulation or anything like that so different programs can use the data in different ways.

like image 603
danmine Avatar asked Dec 04 '08 23:12

danmine


2 Answers

You can store the value in a NUMERIC type with a scale of 0, which will retain the integer semantics required. The NUMERIC type will allow negative numbers, although you could set up a constraint to require 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) would likely work just fine for this data.

like image 157
Ken Gentle Avatar answered Oct 06 '22 05:10

Ken Gentle


AFAIK, You would have to create a custom type. Pointers here although that article is more for restricting negative numbers...

like image 35
JamesSugrue Avatar answered Oct 06 '22 04:10

JamesSugrue