I was having a discussion with a developer at work on the issue of should a table use default values. Is there a hard and fast rule on this or is it a gray area in best practices?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My rule: if many records will use that default (at least initially) then I like to use it as a default. For example, an image table for products in an online store might have a default path of
images/NoPictureYet.png. Eventually, those will get replaced, but for batch loads of data where the pictures simply don’t exist yet (and maybe most of them never will!), a default makes sense (to me, at least).If there is no sensible default (such as “first name” in a customer database – I don’t want MY name defaulted to “FirstName”), then I make it non-nullable and no default – it’s the application’s responsibility to ensure that a correct value gets entered.
But no hard and fast rules on this. It all varies a little 😉