SQLite NULL is the term used to address a missing worth. A NULL incentive in a table is an incentive in a field that seems, by all accounts, to be clear.
A field with a NULL worth is a field with no worth. It is vital to comprehend that a NULL worth is not quite the same as a zero worth or a field that contains spaces.
Syntax
Following is the fundamental linguistic structure of utilizing NULL while making a table.
SQLite> CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
Here, NOT NULL connotes that the segment ought to consistently acknowledge an express estimation of the given information type. There are two segments where we didn't utilize NOT NULL which implies these sections could be NULL.
A field with a NULL worth is one that has been left clear during record creation.
Example
The NULL worth can cause issues while choosing information, since when contrasting an obscure an incentive with some other worth, the outcome is consistently obscure and excluded from the end-product. Think about the accompanying table, COMPANY with the accompanying records −
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
Allow us to utilize UPDATE articulation to set a couple of nullable qualities as NULL as follows −
sqlite> UPDATE COMPANY SET ADDRESS = NULL, SALARY = NULL where ID IN(6,7);
Presently, COMPANY table will have the accompanying records.
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22
7 James 24
Then, let us see the utilization of IS NOT NULL administrator to list down all the records where SALARY isn't NULL.
sqlite> SELECT ID, NAME, AGE, ADDRESS, SALARY
FROM COMPANY
WHERE SALARY IS NOT NULL;
The above SQLite explanation will create the accompanying outcome −
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
Following is the use of IS NULL administrator, which will list down all the records where SALARY is NULL.
sqlite> SELECT ID, NAME, AGE, ADDRESS, SALARY
FROM COMPANY
WHERE SALARY IS NULL;
The above SQLite articulation will create the accompanying outcome.
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
6 Kim 22
7 James 24