Genero Business Development Language - The NULL value (2024)

Several considerations need to be taken regarding SQL columns allowingNULL values.

SQL Basics about NULL

The SQL concept of NULL means "no value" or "undefined value". This is used inSQL to insert or update table rows and omit values for some fields that are not mandatory.

The NULL value is not zero: Zero is a real, numeric and non-null value.

Depending on the database engine, an empty string is null, or non-null. For more details, seeEmpty strings and NULLs.

The [NOT] NULL column constraint

SQL table columns can be defined with the constraint NULL or NOTNULL (to deny NULL values):

CREATE TABLE customer ( cust_id INTEGER NOT NULL PRIMARY KEY, cust_name VARCHAR(50) NOT NULL, cust_creation DATETIME YEAR TO SECOND NOT NULL, cust_address VARCHAR(100) NULL, ...)

When omitting the NULL or NOT NULL constraint in CREATETABLE, most database engines define the column as nullable. However, when no constraint isspecified, some database brands such as Microsoft™ SQLServer deny NULL values in their default configuration. There is an SQL Serverdatabase option for that: See SQL table definition in the SQL Server adaptationguide.

Mandatory information should always be defined with a NOT NULL constraint. Forexample, in an SQL table storing customer information, columns such as the customer name, the rowcreation date/timestamp, columns referencing other tables rows with foreign keys, and obviously theprimary key column, should be defined with the NOT NULL constraint. It is also agood practice to deny NULL values for flag/option columns like a Yes/No status, orgender information.

On the other hand, secondary data such as a comment field, or fields that can only be assignedafter the first row creation (such as update timestamps), should accept NULLvalues.

Comparing NULL values

When NULL values enter in the game, it is important to understand that in means"no value".

When used in comparison, arithmetic expressions, the SQL engine can't do anything withNULL. In such case, the expression usually evaluates to NULL aswell.

Important:

Do not use the = or != operator tocheck for NULL values!

The standard SQL operator to check for NULL values is the IS [NOT]NULLoperator.

SELECT COUNT(*) FROM customers WHERE cust_comment IS NULL

Furthermore, when manipulating non-null values, keep in mind what happens with an operator, whenNULL values can show up. In the next SQL example, without knowing the semantics ofthe != comparison operator, it's not obvious to guess if the lastSELECT statement is supposed to return only the row with value200:

CREATE TABLE tab1 ( col1 INTEGER );INSERT INTO tab1 VALUES (NULL);INSERT INTO tab1 VALUES (100);INSERT INTO tab1 VALUES (300);SELECT SUM(col1) FROM tab1;SELECT AVG(col1) FROM tab1;SELECT * FROM tab1 WHERE col1 != 100;

To simplify the usage of SQL columns that can be NULL, the most database enginesprovide SQL functions to replace a potential NULL value by a default, non-null value:

Table 1. SQL functions for NULL by database brand
Database Server TypeNVL()ISNULL()IFNULL()COALESCE()
IBM® Informix®YesNoNoYes
IBM NetezzaYesYesNoYes
Microsoft SQL ServerNoYesNoYes
Oracle® MySQLNoNoYesYes
MariadDBYesNo YesYes
Oracle DatabaseServerYesNoYesYes
PostgreSQLNoNoNoYes
SAP HANA®NoNoYesYes
SQLiteNoNoYesYes
Dameng®YesYesNoYes

As you can see, the COALESCE() function, which is standard ANSI, issupported by all database engine brands supported by Genero, and since it follows simple SQLfunction syntax, it can be used in static SQL.

Sorting NULL values

When sorting SQL rows with the ORDER BY clause on a column that acceptsNULL values, pay attention to the way the database engine considers nulls versusnon-null values when sorting.

For example, with Informix, when using ORDER BY colname[ASC], rows with NULL appear at the top of the result set. This isdifferent with PostgreSQL, where null values by default sort as if larger than other non-nullvalue.

Table 3. Position of rows with NULL when sorted
Database Server TypeNULL rows position (ASC)
IBM InformixFirst
Microsoft SQL ServerFirst
Oracle MySQLLast
MariadDBFirst
Oracle DatabaseServerLast
PostgreSQLLast
SAP HANAFirst
SQLiteFirst

Consider using NOT NULL constraints for ORDER BY sort columns,when the position of the rows with NULL values matters.

Genero Business Development Language - The NULL value (2024)

FAQs

What does a null value indicate? ›

A null value in a relational database is used when the value in a column is unknown or missing. A null is neither an empty string (for character or datetime data types) nor a zero value (for numeric data types).

What is genero business development language? ›

Genero Business Development Language (BDL) is a program language designed to write an interactive database application . A Genero BDL application is a set of programs that handle the interaction between a user and a database.

What is an example of a null value? ›

A null indicates a lack of a value, which is not the same thing as a zero value. For example, consider the question "How many books does Adam own?" The answer may be "zero" (we know that he owns none) or "null" (we do not know how many he owns).

How do you write a null value? ›

The value null is written with a literal: null . null is not an identifier for a property of the global object, like undefined can be. Instead, null expresses a lack of identification, indicating that a variable points to no object.

What is the common business programming language? ›

Python, Java, JavaScript, C#, C/C++, PHP, Swift, Objective-C, and Kotlin are the top emerging programming languages today.

What is common business language Cobol? ›

COBOL (/ˈkoʊbɒl, -bɔːl/; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural, and, since 2002, object-oriented language.

What does Cobol stand for common business oriented language? ›

What is COBOL (Common Business Oriented Language)? COBOL (Common Business-Oriented Language) is a high-level programming language for business applications. It was the first popular language designed to be operating system-agnostic and is still in use in many financial and business applications today.

What does a null value indicate quizlet? ›

A null value indicates an absent value that many exist but be unknown or that may not exist at all.

What are the reasons for NULL values? ›

NULL values are used to indicate that you could have a value, but you don't know what that value should be yet. They are placeholders until you finally collect the data needed to fill the table field with a real value. You should never confuse NULL values for zeros or blank strings.

Why are NULL values a problem? ›

Although NULL values represent "nothing" or "no value", they are treated as a value by the database. As such, they take up space on the hard drive. So, if you think that you are saving hard drive space by employing NULL values, you could be mistaken.

What happens when it is NULL? ›

Null is database-speak for an empty data field, and often means “data unknown” or “data not available yet”. It sometimes shows up in user interfaces. Often it would be more appropriate to just leave the field blank or leave it out entirely when displaying results. Sometimes null means “not applicable”.

Top Articles
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 6043

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.