开发者

Storing empty strings vs NULLs in MySQL database?

开发者 https://www.devze.com 2023-03-26 00:05 出处:网络
I have a PHP/MySQL application that stores \"开发者_开发技巧blank\" values in some cases as \'\' (empty strings) and in other cases as NULLs.

I have a PHP/MySQL application that stores "开发者_开发技巧blank" values in some cases as '' (empty strings) and in other cases as NULLs.

Having this mixed format certainly causes a problem when comparing, so I’m wondering which one is the better storage mechanism? '' or NULL?


While this is confusing, actually you should store null for a number of reasons :

  1. Checking against null is usually faster than checking an empty string in most databases
  2. Null commonly means "i don't know", empty string means "I know : it's empty". It gives you better semantics.
0

精彩评论

暂无评论...
验证码 换一张
取 消