Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NULL vs NOT NULL [closed]

Tags:

sql

In sql database column, empty fields will be set to NULL unless we specify it using NOT NULL. What are the advantages of using one instead of the other? Thanks!

like image 783
PHP For Life Avatar asked Jul 20 '26 17:07

PHP For Life


2 Answers

If you need to represent unknown data in a column, you make it nullable. If you will always have data in the column, it's better to make it not nullable, as

  1. Dealing with nulls can be annoying and counterintuitive
  2. It saves a bit of space
  3. On some database systems, null values are not indexed.

When a field is set to NOT NULL, it cannot be empty. Which means you have to specify a value for that field when inserting a record.

like image 34
Superman Avatar answered Jul 23 '26 08:07

Superman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!