Column defaults allow you to remove a lot of the hassle of creating records from your code or application logic.
Advantage #1: If you have a table with 2 columns of user information and 20 columns of tinyint/boolean fields, let's say they are privacy settings, and you go to create a new record in that table, without a DEFAULT
value you're going to have to specify every column in your query. There's probably a common setup that you want these records to have by default, and you can set this up using DEFAULT
values. When you INSERT
a record, you only need to specify the two user information fields, and voila, your record is created with a nice set of common privacy settings. You can tweak the flags individually after that.
Advantage #2: Forward compatibility! If you have a bunch of INSERT
s in your code, and then some columns are added on, you're going to have to go back and modify all those INSERT
s if you don't specify a DEFAULT
value (assuming, as is common, that NULL
s aren't going to cut it). Often it isn't necessary to update old code for a new column (since the old code by nature doesn't care about the new column), so this would be a huge pain in the @$$ if you had to start going back and handling every new column in your code as it came along.