Rajat Gupta
Rajat Gupta

Reputation: 26607

Using negative integer range of int (4 bytes) as ids(-2.14 billion to 0) : Any downsides?

I am storing certain entities in my database with integer Ids of size 32 bits thus using the range of -2.14 billion to +2.14 billion.

I have given tried giving some meaning to my ids due to which my Ids, in the positive range, have finished up a bit quickly. I am looking forward to use the negative integer range of -2.14 billion to 0.

Wanted to know, if you could see any downsides of using negative integers as ids, though personally I don't see any downsides.

Upvotes: 1

Views: 600

Answers (2)

Wes
Wes

Reputation: 6585

There is an old saying in database design that goes like this: "Intelligent keys are not". You should never design for special meaning in an id when a descriptive attribute is more appropriate.

Upvotes: 3

Vladimir Dyuzhev
Vladimir Dyuzhev

Reputation: 18336

Given than dumb keys are only compared for equality, sign or lack thereof has no impact.

Upvotes: 1

Related Questions