Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it good practice to set all database columns as NOT NULL?

Tags:

database

Normally is it good practice to set all database columns as NOT NULL or not ? Justify your answer.


2 Answers

No. It's a good idea to set columns to NULL where appropriate.

like image 122
cletus Avatar answered Sep 09 '25 16:09

cletus


I kind of disagree with the "where appropriate" rule. It is actually rather safe to set any column to be NOT NULL; and then later modify the columns to allow NULL values when you need them. On the other hand, if you allow NULL values first and then later decide you don't want to allow them, it can potentially be much more difficult to do this.

It may make your database table/column descriptions quite ugly if you do this excessively, but when in doubt, go ahead and restrict the data.

like image 44
2 revs, 2 users 80%Fragsworth Avatar answered Sep 09 '25 16:09

2 revs, 2 users 80%Fragsworth