NULL vs Empty when dealing with user input

前端 未结 8 1995
一整个雨季
一整个雨季 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

    If the user provides an empty string, I always treat it as null from the database perspective. In addition, I will typically trim my string inputs to remove leading/trailing spaces and then check for empty. It's a small win in the database with varchar() types and it also reduces the cases for search since I only need to check for name is null instead of name is null or name = '' You could also go the other way, converting null to ''. Either way, choose a way and be consistent.

提交回复
热议问题