

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
Not enough gems
Cost: 6 gems
1: Null Values
incomplete
2: Constraints
incomplete
3: Primary Keys
incomplete
4: Foreign Keys
incomplete
5: Schema
incomplete
6: Relational Databases
incomplete
7: Relational vs. Non-Relational DBs
incomplete
This lesson's interactive features are locked, please to keep using them
A key defines and protects relationships between tables. A primary key is a special column that uniquely identifies records within a table. Each table can have one, and only one primary key.
It's very common to have a column named id on each table in a database, and that id is the primary key for that table. No two rows in that table can share an id.
A PRIMARY KEY constraint can be explicitly specified on a column to ensure uniqueness, rejecting any inserts where you attempt to create a duplicate ID.
Run the code. Notice that there's a bug: we have a violation of a PRIMARY KEY constraint on the id column. Fix the data that's being inserted.
When working with integer IDs, it's best practice to increment the id by 1 for each successive insert. Follow this convention when fixing the bug.