Should a reference table include numeric PK identity column value of 0?
We have a table that contains the valid currency codes. We are choosing to use a numeric value as the primary key rather than a 3 char ISO Currency code, for example.
General consensus has concluded that this CurrencyId
column should contain values that begin with zero. Since the US dollar is the primary currency for us, it claimed the first position with a value of 0.
My thought is that identity columns should not start at zero for the sole reason that some languages initialize numerics to zero and as a result the currency code may be uninten开发者_StackOverflow中文版tionally set to USD
when really it was never assigned.
Am I all wet? I would prefer to assign a CurrencyId
of 1 to USD
.
The actual Id should not matter. Having it start at 0 (or 1 for that matter) is completely arbitrary, as that number has no meaning to the user--it is only used by the system as a reference. Whether it starts at 0 or 1 or 4,536,901 is not a critical design decision.
I think the issue that you raise is 100% valid; starting at 0 can cause side effects, some of which may end up as bugs that are subtle and difficult to track down. Avoiding this far outweighs anyone's objection to an abitrary/aethstetic desire to start the numbering at zero.
精彩评论