November 9, 2012 at 2:00 pm
I would like opinions...
Is it good programming practice to have a default constraint on all fields? Will this bog down SQL server?
Thank you.
Mike
November 9, 2012 at 2:42 pm
Constraint checking will be a performance hit on insert and update statements. This is fairly insignificant most of the time. However I would not recommend adding defaults to every column as a general rule. This is not because of performance but because it just doesn't make sense to have a default for so many things. Consider demographic columns. What would you make as the default for DOB or Male/Female. It certainly makes sense that those columns would be NOT NULL but a default doesn't make any sense. Defaults have their place but that place is not on every column. That is my 2¢.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
November 10, 2012 at 3:21 pm
I think constraints are good in general, although they make insert/update operations slower.
In some cases they can help the query execution plans execute faster. As much of the constraints in your database are enabled as more accurate the statistics are, and that is good.
Regards
IgorMi
Igor Micev,My blog: www.igormicev.com
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply