Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good to use a default of NULL?

I have some columns that may contain data that is if the user wants to provide it.

Example | Email | First Name | Last Name |

Email - Required so column is set to NOT NULL - Default: None

First Name - Not Required so column set to NULL - Default: NULL

Last Name - Not Required so column set to NULL - Default: NULL

In phpmyadmin when creating/editing a column; it has an option saying Default: with a drop down showing None | As Defined | NULL | Current Timestamp

Because First Name | Last Name is optional and not required should I choose default NULL or maybe NONE?

Which is best and why please?

I know there are many discussions on this already but I could not find any that answered my question; they was more in regards to allowing NULL or NOT NULL, my question is about default value.

like image 634
PHPLOVER Avatar asked Feb 27 '11 16:02

PHPLOVER


2 Answers

You should set them to Default:Null as if the user doesn't provide any info for that fields, they should be null obviously.

like image 131
Hakan Deryal Avatar answered Sep 21 '22 14:09

Hakan Deryal


Use NULL, None mode is inserting 'None' or some '' string to indicate that there is nothing there....

For more information why you want to use NULL versus a string look here: MySQL, better to insert NULL or empty string?

like image 22
Nix Avatar answered Sep 20 '22 14:09

Nix