If a value con­tains only nu­meric dig­its, when should you store it as a num­ber in the data­base, and when as a string?

Flowchart for when to store value as number or string in the database.
  • Phone num­bers, US ZIP codes, and credit card num­bers can start with a zero: store them as strings.
  • Product prices can be added (multiple prod­ucts), sub­tracted and di­vided (coupons): store them as num­bers.
  • Store as num­ber any sortable re­port col­umn val­ues. Otherwise you’ll get 1, 10, 2” in­stead of 1, 2, 10”.
  • This one is de­bat­able: if you are stor­ing e.g. a US ZIP code, and you are val­i­dat­ing that it only con­tains nu­meric dig­its, should you store it as a num­ber even though you don’t need arith­metic done? I would prob­a­bly still store it as a string, but I would­n’t ar­gue if you make it a num­ber.