Saturday, February 25, 2012

NULL s in database

I am considering not to allow null values in the database.

what are pros and cons ?first, set all field in sqlserver to 'not nullable'
then, in data layer, check whether data inserted are null or not, if any of data is null, refuse to submit data and return false to higher layer|||

erdsah88:

I am considering not to allow null values in the database.

what are pros and cons ?

You cannot do that in a web application because users will go to sites that will not force them to use the site. The only web application you can use more not null tables is HR application in your company's intranet. Hope this helps.

|||

erdsah88:

I am considering not to allow null values in the database.
what are pros and cons ?


This isn't an easy question, as I suspect you've already figured out. The basic question is whether your application needs to make a distinction between default values (zero for numbers, empty strings, etc.) and missing information.

You need to carefully consider whether you need to know if data ismissing. For example, without nulls, does a zero-length string in theMiddleName field for a person mean that you don't have the middle nameor that the person doesn't have a middle name. Do you care about whichit is?

If you don't need to know when information is missing versus non-existant, it is much easier to disallow nulls. This will eliminate much of the need to do conversions between nulls and .NET data types that don't allow nulls. If you don't have the person's income, just put zero in that field and be done with it.

For an interesting take on using nulls, see Adam Cogan'sRules to better SQL Server Databases, rules 100 and 101.

Hope this helps!
Don

No comments:

Post a Comment