4

I need to store ulong values as a primary key in SQL Server. Since SQL Server doesn't have a ulong datatype (or for that matter anything unsigned), the only way to go is to have column as varbinary(8).

Now, having a varbinary as a PK doesn't sound like a good idea. So what are the alternatives to store ulong values?

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Paul White
    Aug 29, 2017 at 10:24

1 Answer 1

4

I'm assuming by ulong that you mean a 64-bit unsigned integer.

Your best option if you truly need to span the entire range of a ulong is to use NUMERIC(20,0) or larger. If you need to enforce the range of values to those valid for your data type, use a check constraint to restrict the values to between 0 and 18,446,744,073,709,551,615. Alternately, you could use VARBINARY(8), but your application would have to be base-aware.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.