← RGPV CS-502 DBMS December 2024 solved question paper
RGPV Previous Year Examination Question
B.Tech. V Semester | CS-502 (GS) | December 2024 | 2(b)
Question (restated): Describe why NULL values are important in the relational model.
Answer
Meaning of NULL
NULL is a special marker representing missing, unknown or inapplicable information in a relational database. It is not zero, an empty string or a blank space. For example, a student’s examination marks may be unknown until evaluation is complete, while a spouse name may be inapplicable.
Importance
NULL allows incomplete records to be stored without inventing values. It also represents missing information introduced by outer joins. However, it requires careful treatment because ordinary comparisons involving NULL generally produce UNKNOWN rather than TRUE or FALSE.
Three-valued logic
SQL uses TRUE, FALSE and UNKNOWN. A WHERE clause retains only rows for which its condition evaluates to TRUE. Thus, neither marks = NULL nor marks <> NULL is a reliable test for missing values. Use IS NULL or IS NOT NULL instead.
| ID | Marks |
|---|---|
| 1 | 80 |
| 2 | NULL |
| 3 | 60 |
SELECT ID FROM Student WHERE Marks IS NULL; SELECT AVG(Marks), COUNT(Marks), COUNT(*) FROM Student;
The first query returns ID 2. The second returns 70, 2 and 3 respectively: AVG and COUNT(column) ignore NULL, whereas COUNT(*) counts all rows. Replacing missing marks with zero would incorrectly change the average to about 46.67.
Constraints and handling
A primary key cannot contain NULL because it must identify every row. A NOT NULL constraint makes an attribute mandatory. A nullable foreign key may represent an optional relationship, subject to the applicable referential constraint. UNIQUE constraint treatment of NULL can differ across database products.
SELECT COALESCE(Marks, 0) FROM Student;
COALESCE returns the first non-NULL argument. Such substitution should be used only when zero is a meaningful default, not as a general replacement for unknown values. Proper NULL handling preserves data semantics and prevents misleading query results.
Further reading
Silberschatz, Korth and Sudarshan, Database System Concepts; Elmasri and Navathe, Fundamentals of Database Systems.
Discussion
Ask a question, share your thoughts or report an error.
Sign in to participate in the discussion.
Join the discussion