If this question is too broad, my apologies. I am a DBA and I am working with a developer that thinks column defaults are a bad idea and that just setting the column to disallow nulls is good enough.
I am looking for the benefits of column defaults from the developers point of view. Thank you for your comments.
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
DEFAULTvalue 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 usingDEFAULTvalues. When youINSERTa 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
INSERTs in your code, and then some columns are added on, you’re going to have to go back and modify all thoseINSERTs if you don’t specify aDEFAULTvalue (assuming, as is common, thatNULLs 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.