0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
To be compliant with first normal form, a database table simply needs to follow 2 rules:
name | age | |
---|---|---|
Lane | 27 | lane@boot.dev |
Lane | 27 | lane@boot.dev |
Allan | 27 | allan@boot.dev |
This table does not adhere to 1NF. It has two identical rows, so there isn't a unique primary key for each row.
The simplest way (but not the only way) to get into first normal form is to add a unique id
column.
id | name | age | |
---|---|---|---|
1 | Lane | 27 | lane@boot.dev |
2 | Lane | 27 | lane@boot.dev |
3 | Allan | 27 | allan@boot.dev |
It's worth noting that if you create a "primary key" by ensuring that two columns are always "unique together" that works too.
First normal form is simply a good idea. I've never built a database schema where each table isn't at least in first normal form.
We hired an intern at CashPal and her first task was to design a new "companies" table. This table will store our business client's data. Unfortunately, the intern has committed the unforgivable sin - there's no primary key on this table! We could have entire duplicate rows!
Add an id
field as the first column. It should be an integer and have a PRIMARY KEY
constraint on it. When you're done, the companies
table will be in first normal form.
Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution