Is it good to use the default value of NULL?

I have several columns that may contain the data that the user wants to provide.

Example | Email | Name | Surname |

Email - required column is set to NOT NULL - default: None

Name - Not required, so the column is set to NULL - Default value: NULL

Last name - Not required, so the column is set to NULL - Default value: NULL

In phpmyadmin when creating / editing a column; it has an option saying Default: drop-down list No | As defined | NULL | Current timestamp

Because Name | Is the surname optional and not required if I should select NULL by default or maybe NONE?

Which is better and why do you like it?

I know that there is already a lot about it, but I could not find the answer to my question; they were more about NULL or NOT NULL permission, my question is about the default value.

+4
source share
3 answers

You should set them by default: Null, as if the user did not provide information for these fields, they should be zero.

+10
source

Use NULL, None mode inserts "None" or some "string" to indicate that there is nothing there.

For more information, why do you want to use NULL compared to a string, see here: MySQL, is it better to insert NULL or an empty string?

+7
source

If you plan on indexing these NULL columns, you really get performance issues on large tables (with over 1 million rows ...). However, using an empty string or NULL as a string ("null") for the default value can increase the performance of your request in these cases. By the way, I’m not saying that NULL is evil, but these are the cases that we have encountered in the telecommunications business.

0
source

Source: https://habr.com/ru/post/1341525/


All Articles