简体   繁体   中英

MySQL Null or empty fields - New Database Design

I'm designing a new database and currently there a many fields that end up with the value NULL.

I've read about NULL vs "" and I think that "" is preferred.

Should I go to the effort to ensure there are no NULL values - it would only take a few hours?

Is this worth the effort - Note: I will be working with this database for many years to come.

thx

A simple hint: If you "end up" with many fields being NULL in a table , this is probably the sign that you should split your table in two, using a JOIN operation to retrieve data when needed...


Concerning NULL vs "" remember few things:

  • NULL is the standard SQL way to say "non existent data"
  • NULL is usable both for text and non-text columns. "" is for text-only
  • aggregate functions like COUNT() will ignore NULL values but not ""
  • Column having UNIQUE index allow several rows having a NULL value. But not several rows having "" as value

Start will null values and see how it goes. I think it's a simple enough procedure to update where is null to "".

This question is very similar and has a great answer arguing between null and "". MySQL, better to insert NULL or empty string?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM