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 building Yet Another Address Book and there is a post code field. Provided that post codes are always a 4 digit number, which data type do I store it as? Integer or string? Technically it is an integer, but I’m not doing any sort of calculations on it, I’m just spitting it out into a table. Would your opinion change if I want to sort the table by post code?
Now, I’m not stupid. I do recognize a valid need for integers, such as page views and unique users or logged in users and guest users. But what about for storing how many files are in a torrent? Integer or string?
In my country, post-codes are also always 4 digits. But the first digit can be zero.
If you store ‘0700’ as an integer, you can get a lot of problems:
Technically, our post codes is actually strings, even if it is always 4 digits.
You can store them as integers, to save space. But remember this is a simple DB-trick, and be careful about leading zeroes.
That’s clearly an integer.