Table of Contents
This guide covers null value in SQL with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.
NULL in SQL Is the term used to represent a missing value. The NULL value in a table is the value in an empty field. Field with NULL value is a field with no value.
Note : The field contains a NULL value other than a field with a value of zero (zero value) and a field containing a space (space).
Syntax
The basic syntax of NULL during table creation is:
SQL> CREATE TABLE NHANVIEN(ID INT NOT NULL,TEN VARCHAR (20) NOT NULL,TUOI INT NOT NULL,DIACHI CHAR (25) ,LUONG DECIMAL (18, 2),PRIMARY KEY (ID));
Here, NOT NULL indicates that the column must always accept a certain value of the given data type. There are two columns that do not use NOT NULL, meaning that these columns can be NULL.
Fields with NULL values are fields that are left blank during record creation.
Example of NULL Value
NULL values can cause some problems while selecting data, because when comparing an unspecified value to any other value, the result is always an unknown result.
You must use the IS NULL or IS NOT NULL operators To check a NULL value.
Considering the table NHANVIEN Has the following records:
+----+----------+-----+-----------+----------+ | ID | TEN |TUOI | DIACHI | LUONG | +----+----------+-----+-----------+----------+ | 1 | Thanh | 32 | Haiphong | 2000.00 | | 2 | Loan | 25 | Hanoi | 1500.00 | | 3 | Nga | 23 | Hanam | 2000.00 | | 4 | Manh | 25 | Hue | 6500.00 | | 5 | Huy | 27 | Hatinh | 8500.00 | | 6 | Cao | 22 | HCM | | | 7 | Lam | 24 | Hanoi | | +----+----------+-----+-----------+----------+
The following is the usage of the IS NOT NULL operator In SQL:
SQL> SELECT ID, TEN, TUOI, DIACHI, LUONGFROM NHANVIENWHERE LUONG IS NOT NULL;
The result is:
+----+----------+-----+-----------+----------+ | ID | TEN |TUOI | DIACHI | LUONG | +----+----------+-----+-----------+----------+ | 1 | Thanh | 32 | Haiphong | 2000.00 | | 2 | Loan | 25 | Hanoi | 1500.00 | | 3 | Nga | 23 | Hanam | 2000.00 | | 4 | Manh | 25 | Hue | 6500.00 | | 5 | Huy | 27 | Hatinh | 8500.00 | +----+----------+-----+-----------+----------+
And the usage of the IS NULL Operator in SQL is as follows:
SQL> SELECT ID, TEN, TUOI, DIACHI, LUONGFROM NHANVIENWHERE LUONG IS NULL;
The above example will return the result:
+----+----------+-----+-----------+----------+ | ID | TEN |TUOI | DIACHI | LUONG | +----+----------+-----+-----------+----------+ | 6 | Cao | 22 | HCM | | | 7 | Lam | 24 | Hanoi | | +----+----------+-----+-----------+----------+
In the next article, Quantum will discuss with you how to create a temporary name using ALIAS in SQL. Have you remembered to it!
Previous article: The clause combines UNION data in SQL
Next lesson: Create a temporary name using ALIAS in SQL
FAQ
What should I check before following these steps?
Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.
Why might the process not work?
Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.
Can I undo the changes if necessary?
That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.
Reader Comments 0
Sign in with email or Google to join the discussion.