Sub topic 15
First Normal Form
This chapter assumes you know what a relation, tuple, attribute and domain are, and that you have read the previous chapter on redundancy and update anomalies. First normal form (1NF) is the entry level of the normal-form ladder. Every later form (2NF, 3NF, BCNF) assumes it.
What 1NF requires
A relation is in 1NF if the domain of every attribute contains only atomic values, and every row holds exactly one value from that domain in each column. An atomic value is one the database treats as indivisible. In practice this rules out three things:
- Multivalued attributes, such as a
phonescolumn holding'98450, 98451'. - Composite attributes stored as one column, such as a single
addresscolumn holding street, city and PIN code together. - Repeating groups, such as columns
phone1,phone2,phone3that hold the same kind of fact.
Atomicity depends on how the data is used. A date is atomic if queries never need its day or month separately. If a query regularly extracts the city from an address string, the address is not atomic for that application.
Many textbooks also require a key to exist, so that rows are unique and row order carries no meaning. Under this reading, a table with duplicate rows and no key is not a relation, so it is not in 1NF.
Why it matters
The cost shows up in queries and in constraints. Consider a table with a comma-separated list:
| student_id | name | phones |
|---|---|---|
| 1 | Asha | 2221, 3332 |
| 2 | Ravi | 22210 |
Finding the student with phone 2221 needs a pattern match. LIKE '%2221%' wrongly matches Ravi's 22210. You cannot declare the phone unique, cannot add a foreign key on it, and cannot add or remove one number without rewriting the whole string. Those are the update anomalies from the previous chapter, appearing inside a single cell.
Converting to 1NF
There are three standard fixes, depending on the kind of violation.
- Composite attribute: replace it with one column per component (
street,city,pin). This is the same rule the ER-to-relational mapping uses. - Multivalued attribute, preferred fix: move the attribute to its own table whose key combines the owner's key and the value. This is also how the ER mapping handles multivalued attributes.
- Multivalued attribute, flattening: repeat the row once per value. This is valid 1NF, but it copies
nameinto every row, which causes the redundancy that 2NF and 3NF address.
The preferred repair of the phone example:
CREATE TABLE student (
student_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL
);
CREATE TABLE student_phone (
student_id INT,
phone VARCHAR(15),
PRIMARY KEY (student_id, phone),
FOREIGN KEY (student_id) REFERENCES student(student_id)
ON DELETE CASCADE
);
INSERT INTO student VALUES (1, 'Asha'), (2, 'Ravi');
INSERT INTO student_phone VALUES (1, '2221'), (1, '3332'), (2, '22210');
SELECT s.name
FROM student s
JOIN student_phone p ON p.student_id = s.student_id
WHERE p.phone = '2221';The query returns only Asha. Equality on an atomic column replaces the fragile pattern match. The composite primary key stops the same number being stored twice for one student, and the foreign key removes a student's numbers when the student is deleted.
Common errors
- Treating a composite attribute as always allowed. A composite attribute is fine in an ER diagram. It must be flattened when you build the table.
- Assuming repeating columns are 1NF.
phone1, phone2, phone3has only atomic cells, but it still encodes a repeating group. It fixes the maximum count at design time and makes searching awkward. GATE questions normally treat it as a violation. - Believing 1NF removes redundancy. The flattened version in fix 3 is in 1NF and still repeats
name. 1NF only guarantees atomic values. - Confusing a key with atomicity. A table can have atomic cells and still violate 1NF under the stricter reading if it has no key and allows duplicate rows.
Nested structures in real systems
PostgreSQL arrays, JSON columns and nested types in other systems store non-atomic values on purpose. In theory they break 1NF. In practice they are acceptable when the value is only stored and returned whole, and never joined on, constrained or searched by element. If you need those operations, use a child table.
Exercise
The relation course(course_id, title, instructors) stores instructors such as 'Rao, Iyer' in one cell. Give a 1NF design that avoids copying title into several rows, and state the primary key of each table.
Show answer
Use two tables: course(courseid, title) with primary key courseid, and courseinstructor(courseid, instructor) with primary key (courseid, instructor) and courseid as a foreign key to course. Each cell is atomic, and title is stored once per course.
Exercise
A relation has columns emp_id, name and address, where address stores 'MG Road, Pune, 411001' as one string. Is it in 1NF? Explain what you would change.
Show answer
Not under the usual rule, because address is a composite value whose parts (street, city, PIN) are used separately. Replace it with the columns street, city and pin. If the application only ever prints the address whole and never searches by part, the single column could be treated as atomic.