Storing a really large number in SQL Server

biginteger, c#, sql, sql-server-2008

Solution

A pertinent question to ask yourself in this kind of situation, and one I asked of you in a comment, is the following:

Is your really large number meant to be used as a number for arithmetic, or is it just some identifier?

And you responded

From what I understand is, the number is issued from an Oracle system from some governmental agency as a unique identifier, it can be as long as 0 - 50 number in length and we need to store that in our application

And that should lead you to a different answer than trying to store the data as numeric.

If it's just an identifier, then you really don't need to store or treat it as numeric. Strings composed of digits, such as Social Security Numbers in the United States or account numbers on credit cards and loans are not really numbers, from a data standpoint. They are identifier strings. Store them that way.

Problem

How would I store a large number like `92233720368547758079223372036854775807922337203699` in SQL Server 2008? Max `bigint` allows is `9223372036854775807` I guess one approach I could take is to do following, store the number as `varchar(50)` and in C# code I could do is ``` BigInteger x = BigInteger.Parse("922337203685477580792233720368547758079223372036"); ``` Would appreciate any feedback. Thanks

Original source