5

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 unintentionally set to USD when really it was never assigned.

Am I all wet? I would prefer to assign a CurrencyId of 1 to USD.

Chad
  • 23,658
  • 51
  • 191
  • 321
  • 2
    Whatever you decide - just make sure to clearly document that somewhere, and get agreement from all developers and DBA's about the solution you picked! Also: if you do use `0` as a "real" value, you could still always pick e.g. `-1` as a placeholder value for "unknown" or "undefined" and set the columns referencing this table to use that value as a default. – marc_s Sep 15 '11 at 12:49
  • 2
    @Chad - I agree with you. [This question has a similar sort of discussion about enums](http://stackoverflow.com/questions/7257409/should-an-enum-start-with-a-0-or-a-1/7257458#7257458) – Martin Smith Sep 15 '11 at 13:15

1 Answers1

3

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.

Phil Sandler
  • 27,544
  • 21
  • 86
  • 147