views:

221

answers:

2

I want to make my fields as small as I can, but at the same time I don't want to have to go back and make them bigger later.

I was wondering if there is some sort of quick reference for field sizes and/or types for common database fields.

i.e., What is reasonable for an email field? 50? 100?

Or is this not something I should worry about?

+1  A: 

Here is a related post that might help to answer your question...

http://stackoverflow.com/questions/472434/database-column-sizes-for-character-based-data

Brian Behm
+1  A: 

If you use VARCHAR() (or NVARCHAR() ), you do not need to worry too much about setting a slightly high initial value, and on most DBMS, there is no data loss nor real cost in increasing the size post-facto.

On most DBMS there is a cost for using at least one varchar field in a table, but that cost is the same whether you have one or several varchars. The per-row cost of defining a table with at least one varchar field is nominal (one or two bytes), and is typically offset by the saving of not storing all these long strings.

Using fixed length char types, one would need to allow, say in the order of 40 chars at a minimal, for email addresses, since such long addresses are not all that uncommon, but this would waste probably 15 to 20 bytes for most rows, since most email addresses probably average a length circa 20-25 (maybe even less).

So in a nutshell, and unless the dataset has record counts in the millions+ and performance is a major concern, using VARCHAR and similar types allows not have to make hard choices (and indeed hard to change choices), regarding the maximum allowed length of individual fields.

mjv