I have a form on a website which has a lot of different fields. Some of the fields are optional while some are mandatory. In my DB I have a table which holds all these values, is it better practice to insert a NULL value or an empty string into the DB columns where the user didn’t put any data?
Share
By using
NULLyou can distinguish between “put no data” and “put empty data”.Some more differences:
A
LENGTHofNULLisNULL, aLENGTHof an empty string is0.NULLs are sorted before the empty strings.COUNT(message)will count empty strings but notNULLsYou can search for an empty string using a bound variable but not for a
NULL. This query:will never match a
NULLinmytext, whatever value you pass from the client. To matchNULLs, you’ll have to use other query: