When to make mysql fields NULL and NOT NULL... I'm completely lost.
I know the basic stuff perfectly. However, my problem is when to do a field NULL or NOT NULL => ONLY IN A PERFORMANCE PERSPECTIVE.
Thank you for your help.
If NULL is specified, the field is allowed to be left empty. If NOT NULL is specified, the field must be given a value. In the absence of either a NULL or NOT NULL, NULL is assumed.
From this article.
When it says 'the field is allowed to be left empty' this means when doing an INSERT query, and the opposite goes for NOT NULL.
Hope this helps 😉
Unless you know a specific reason to do so -- and at this point you apparently don't -- take my avuncular advice and make all columns NOT NULL. The performance differences in a relatively small size database are negligible.
Small size means any database you would ever be working on if you didn't by now know the precise differences between null and not null and when to use each. That would be highly expert level stuff to consider.
Most database engines are optimized to handle NOT NULL field checking quickly, so there's no real performance gain from one or the other.
IOW, like nemonomansaid, choose NULL or NOT NULL based on the needs of your data, not performance.