NULL vs Empty when dealing with user input

前端 未结 8 2021
一整个雨季
一整个雨季 2021-02-06 11:57

Yes, another NULL vs empty string question.

I agree with the idea that NULL means not set, while empty string means \"a value that is empty\". Here\'s my problem: If the

相关标签:
8条回答
  • 2021-02-06 12:36

    I try to keep things simple. In this case, I'd make the first-name column not-nullable and allow blanks. Otherwise, you'll have three cases to deal with anywhere you refer to this field:

    1. Blank first name
    2. Null first name
    3. Non-blank first name

    If you go with 'blank is null' or 'null is blank' then you're down to two cases. Two cases are better than three.

    To further answer your question: the user entering data probably doesn't (and shouldn't) know anything about what a "null" is and how it compares to an "empty". This issue should be resolved cleanly and consistently in the system--not the UI.

    0 讨论(0)
  • 2021-02-06 12:40

    While your example is mostly for strings, I like to say that I use null for numerical and boolean fields. An accountbalance of 0 is very different to me as one that is null. Same for booleans, if people take a multiple choice test with true and false answers, it is very important to know whether someone answered true or false or didn't answer at all. Not using null in these cases would require me to have an extra table or a different setup to see whether someone answered a question. You could use for instance -1 for not filled in 0 for false and 1 for true, but then you're using a numerical field for something that's essentially a boolean.

    0 讨论(0)
提交回复
热议问题