I am working on a database design and would like to store user addresses. Consider the following: Many times when you register your address with a website there is 'address line 1' and 'address line 2'.
Since 'address line 2' is optional what is the best practice for storing it?
Would you want to use a single table and allow 'address line 2' to be NULL or would you want to create a separate table with a one-to-one relationship?
FYI using MySQL for my database.
None of the Above - A non-nullable field that defaults to a single-space. Where you can, avoid the headaches of having to coalesce your nullable fields. to get intuitive Boolean results
The real reason why it is wrong to create a separate table, in this instance, is that the address label only has room for two address lines. Therefore store the two address lines in the main table.
In other circumstances the maximum number of possible values is truly unknown, so a separate table is (at least theoretically, there can be overriding considerations of practicality) correct.
Update: Note that in this example, the value of all spaces is already a special value that must be handled specially - by omission on the printed address label (or other display medium). Adding an additional special value, NULL, with the identical semantics and handling on the printed lable is wasteful ad unnecessary.