June 2010
Intermediate to advanced
328 pages
7h 51m
English
There are two ways you might fill the perceived gap.
Instead of allocating a new primary key value using the automatic pseudokey mechanism, you might want to make any new row use the first unused primary key value. This way, as you insert data, you naturally make gaps fill in.
bug_id | status | product_name |
|---|---|---|
1 | OPEN | Open RoundFile |
2 | FIXED | ReConsider |
4 | OPEN | ReConsider |
3 | NEW | Visual TurboBuilder |
However, you have to run an unnecessary self-join query to find the lowest unused value:
| Neat-Freak/anti/lowest-value.sql | |
| | SELECT b1.bug_id + 1 |
| | FROM Bugs b1 |
| | LEFT OUTER JOIN Bugs AS b2 ON (b1.bug_id + 1 = b2.bug_id) |
| | WHERE b2.bug_id IS NULL |
| | ORDER BY b1.bug_id LIMIT 1; |
Earlier in the ...
Read now
Unlock full access