Integer vs String in database

前端 未结 16 598
后悔当初
后悔当初 2020-12-05 13:42

When defining datatypes in a database, I have always had a problem with choosing whether to use integers or strings to store certain \'numerical\' data.

Say I am bui

16条回答
  •  时光取名叫无心
    2020-12-05 14:24

    Well as far as postcodes go, this is a typical UK postcode:

    EC2R 6PK
    

    In university my databases lecturer told me something that has stuck with me and still holds 15+ years later:

    If you perform arithmetic on it, store it as a number. Otherwise it's a string.

    Frankly I don't think you can go wrong with that advice.

    Obviously you don't perform arithmetic on postcodes, therefore they're strings.

提交回复
热议问题