Search Helium

Home > Computers & Technology > Software > Software & Web Development

Databases: Understanding NULL values

by Jeffrey Ober

Created on: November 12, 2009


The NULL value is nothing. Well, technically, its not actually nothing, its something that just happens to represent nothing. So NULL is something that is actually nothing.

In computers, the only possible things that exist are the numbers one and zero. Everything else absolutely must be some variation on those two numbers. Fortunately for people, the ASCII code was developed which gives the computer a way to represent letters and decimal numbers that people understand (using those ones and zeros). At the same time, a process had to be developed to represent nothing. That is a special ASCII value (NULL).

In a database, when you set up the database, you have to define the fields that are in the tables. These fields are defined and set up for various different types of data. However, when you set up a field for a number, there has to be a difference between the number zero and no number at all. That's what the NULL value is for - when you haven't placed any value at all in the field, there's nothing there. When there's nothing there, that's NULL. If instead, you place a zero in a field, that's a value. That's a number. That's not nothing.

A similar situation arises when working with string fields in a database. If a field is set up to contain a string value, the field will need to contain numbers, letters, and symbols. If a blank space needs to be added into the field, the field must have the capability of holding a space. However, if the space is removed, or if nothing is added to the field, then the field will contain the NULL value.

When reading or writing information to the database tables, the NULL value is also useful for checking the contents of the table. When reading a value from the table, you can compare the value read to the NULL value to determine if anything actually exists in the table you just attempted to read. You can also do the same when inserting a value into a table - check the value to be entered with NULL, and if it is equal to NULL, you're going to insert nothing.

In some cases, when the database is set up, a condition put on the fields may be "not NULL." This condition will make it so that a record cannot be added to a table unless the field contains some value. Without this condition, you can add a record that has blank fields. Depending on your use of the fields, you may wish to allow a certain field to be blank or not. For example, you may set up a table to track customers and require a customer name, but make the phone number optional. The name field would have a "not NULL" requirement, but the phone number field would not.

Just remember - NULL represents nothing, but it has to be something, so that something is nothing.

Learn more about this author, Jeffrey Ober.
Click here to send this author comments or questions.

Helium Debate

Cast your vote!

Which is a better Web application framework: Ruby on Rails or PHP?

Click for your side.

Featured Partner

Catalyst Music inc

more


CONNECT WITH US

Read
our blog
Helum for writers

Write and get published
Share with other writers
Polish your freelancing skills

Join our active writing community
Helium Content Source for Publishers

Quality articles from proven freelancers
Exclusive rights, fast turnaround
Brand engagement, business blogging -- our writers do it all

Get custom content today!

INFORMATION


Helium, Inc.
200 Brickstone Square Andover, MA 01810 USA
#