Skip to content

The loop inside the database

Two ways to give every student in college 7 an extra 10 XP.

```sql -- A UPDATE students SET xp = xp + 10 WHERE college_id = 7;

-- B DECLARE c CURSOR FOR SELECT id FROM students WHERE college_id = 7; -- open, fetch each id, UPDATE students SET xp = xp + 10 WHERE id = <that id> ```

College 7 has 8,000 students. What is the main reason B is slower?