MySQL - Usage of 'Allow NULL'
Does usage of NULL to fill empty cells on my tables make searches / queries faster?
For example is this
90 2 65 2011-04-08 NULL NULL
134 2 64 2011-04-13 NULL 07:00:00
135 2 64 2011-04-13 N开发者_如何学GoULL 07:00:00
136 2 64 2011-04-13 NULL 22:45:00
137 2 64 2011-04-14 NULL 19:30:00
better than
90 2 65 2011-04-08
134 2 64 2011-04-13 07:00:00
135 2 64 2011-04-13 07:00:00
136 2 64 2011-04-13 22:45:00
137 2 64 2011-04-14 19:30:00
If anyone could tell me any specific advantage to using NULL (performance, good practice, etc) that would be much appreciated.
There is a semantic difference.
NULL
means "value unknown or not applicable".
If this describes the data for that column, then use it.
- The empty string means "value known, and it's 'nothingness'".
If this describes the data for that column, then use it. Of course, this applies only to strings; it's unusual to have such a scenario for other data types, but usually for numeric fields a value of 0
would be appropriate here.
In short, it depends mostly on what your fields mean. Worry about performance and profiling later, when you know what data you're representing. (NULL
vs ""
is never going to be your bottleneck, though.)
精彩评论