mattytommo mattytommo - 3 months ago 16
C# Question

SQL equivalent of C# BigInteger

So, I've been using the new

BigInteger
class introduced in .NET 4 to store incredibly large numbers.

Now, I've started thinking about saving these numbers to the database (SQL Server). My question is, is this even possible? As far as I know and what I've researched, the SQL data types do not contain a property that corresponds to the behaviour of
BigInteger
(theoretically no min or max).

The closest I've seen is
bigint
, but that has a minimum of
-2^63 (-9,223,372,036,854,775,808)
and a maximum of
2^63-1 (9,223,372,036,854,775,807)
.

Answer

If your SQL server's DECIMAL type does not support the precision you need you'll only have the option to store the number as a string or a binary, i.e. in a VARCHAR, TEXT or `VARBINARY`` field.