Which is better? Using the setting NOT NULL and providing a value in the web application or using NULL and not providing the value.
| SitePoint Sponsor |

Which is better? Using the setting NOT NULL and providing a value in the web application or using NULL and not providing the value.
--
sethtrain





That depends. What are you trying to accomplish? Do you understand nulls and why they are used?
Basically using NULLS means that you can have an absence of values. If you are keeping a record of test scores for instance, and can have students who have not written the tests then you would want to use NULLS in that field. If you entered any other value that would be wrong. So for instance if you used NOT NULL and entered a value of 0 or 99999 (an impossible score for instance) to represent someone not taking the test both of those would technically be incorrect.

What I will be using should always have a value and the reason I ask this is because I could make NOT NULL and have the database send the error if the value isn't included or build in the validation myself. I didn't know what would be correct.
--
sethtrain




leaving a field as NULL is there for a reason.
If data is not required, don't put something in it.


in that case, make it NOT NULLOriginally Posted by sethtrain
feel free to use NOT NULL with DEFAULT, in which case you don't have to submit the value at all
with NOT NULL but no DEFAULT, it will bomb if you don't supply the value
make sure it isn't a phony value, though
Bookmarks