From your comment, if you are not doing any arithmetic (i.e. this is just an identifier), this is optional - and probably just shouldn't be - a number in the first place. Just consider it as a string both in the database and in the consumer application and move on.
However, for future visitors to the question who has a number, there are two options that I can think of:
- Use
varchar and BigInteger.Parse(string) / BigInteger.ToString() - Use
varbinary and BigInteger..ctor(byte[]) / BigInteger.ToByteArray()
When migrating to a binary route, there may be an advantage in performance or space, but it may also limit other applications that should use the value. IMHO, although if you do not disassemble many of them per second, I doubt that it really is a hassle - and these days, storage is cheap.
In addition, strings are currently the actual serialization method (e.g. XML or JSON), and storing in varchar will also allow you to use SQL Server XML functions right out of the box.
The third option is to specifically create a CLR type to port BigInteger , so you can use it directly in SQL Server (i.e. for comparison and arithmetic). Again, not sure if it's worth the hassle though.
source share