Click here to Skip to main content
15,895,813 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I have a confusion, Is there any disadvantage of apply default constraints over every fields of DB table .

I want to apply default constraints at every fields of table, So whenever , I save any data into DB table, than it should be save with some default value rather than null,
Posted
Comments
Tomas Takac 18-Apr-15 15:13pm    
Maybe there would be a slight performance hit with bulk insert but otherwise should be ok. But it's hard to imagine why would you want to do such thing in the first place.
Sergey Alexandrovich Kryukov 18-Apr-15 19:04pm    
I basically agree. But why taking care of performance, if the logic and the functionality can endangered? Please see my other comment below.
—SA
Sergey Alexandrovich Kryukov 18-Apr-15 19:02pm    
The question does not really make sense, because of one apparent reason: to discuss "advantages" or "disadvantages", you have to describe two or more alternatives? What alternatives do you suggest to consider? I don't know. If your application's semantic involves some non-default constraints, which is more than likely, do you think you have a choice? Or do you want to carry the constraints out of the database schema and implement them in some application programs (remember, you might have more than on over the same database), ask yourself: how these rules can be data-driven? If they are not, it would be a really bad idea. Especially if you have more than one application program. Imagine the situation: one application can populate some data which is not valid from the standpoint of another application. Do you think it can be acceptable?
—SA
—SA
W Balboos, GHB 24-Apr-15 14:10pm    
Ask yourself "why do I need a default constraint?".

The reason to a default value for a field is that you wish to, at times, omit entering a value in a field when you insert a new record and NULL (the default default) is unacceptable.

Per Sergey, above, you have to be aware of what will now (and may in the future) access the table.

Some fields, on the other hand, beg a default constraint, such as the creation time of a record. Although I use this commonly, it is rare, indeed, that I put in any other default values for a field. You can always handle NULL in your queries and thus avoid the risk of unintended consequences down the line.

1 solution

The DEFAULT constraint is used to insert a default value into a column.

The default value will be added to all new records, if no other value is specified.

if u use this constraint across all columns means u can't able to insert the null values.

Other than this there will not be any disadvantages happen
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900