Last post Jun 19, 2011 06:04 AM by suresh_g_v2002
Jun 19, 2011 04:04 AM|lautaro.arino|LINK
Im planning a pet-rat family tree application.
In teh db planning face i always get stuck with if i should allow nulls or not. Some columns are a no brainer ofcourse, but im thinking about the rat properties that may not contain info. Like for example the parents of the rat wich may not be known. Or
"comments", or "decease history" .
How should i think? Wiich are the pros and cons?
Jun 19, 2011 05:48 AMemail@example.com|LINK
Good question, simple answer though.
If the column could be null set it as a nullable type, or else you will have to supply a value before performing an insert on the row.
If you are using the EF or Linq 2 SQL you will get the nullable type property ie int?, decimal? datetime? (although strings can never be null in .Net).
So if its null in EF or Linq 2 Sql this is very easy to tell.
//decimal? (nullable in db)
if(myNullableDecimal.HasValue) //not null
myNullable.Value += 10; //value is the non-nullable value, when it is not nullable.
Jun 19, 2011 06:04 AM|suresh_g_v2002|LINK
Basically this shoud be decided as per the client requirements .., if the client says there should be some mandatory data in the database fields then do not allow nulls...,
If you are the deciding factor..
my suggestion is better allow nulls for least priority fields..., so that you can skip the client side and server side validations