This is a particularly annoying issue that I can't seem to find a way around. I'll probably wake up at 2am with the solution, but I figured I'd post here first.
Let's say I have a list of book pages stored in a SQL table, with an ID, page number and page contents. By selecting ordered by page number the pages will be displayed in the right order. Easy.
Now let's say I want to insert a new page 3. The old page 3 becomes page 4, old page 4 becomes page 5... Also easy.
Now let's say that I'm not allowed to rename existing page numbers when I insert a new page. How do I structure the table to allow for new pages to be inserted?
Extra columns are allowed.
I could number the pages 10, 20, 30 etc instead of 1,2,3. My new page 3 could then be given number 25 and the original page order would be maintained.
The same effect could be attained with decimals too.
Those seem like very hacky, short-sighted solutions though.
Surely there's a "right way" to do this?
Let's say I have a list of book pages stored in a SQL table, with an ID, page number and page contents. By selecting ordered by page number the pages will be displayed in the right order. Easy.
Now let's say I want to insert a new page 3. The old page 3 becomes page 4, old page 4 becomes page 5... Also easy.
Now let's say that I'm not allowed to rename existing page numbers when I insert a new page. How do I structure the table to allow for new pages to be inserted?
Extra columns are allowed.
I could number the pages 10, 20, 30 etc instead of 1,2,3. My new page 3 could then be given number 25 and the original page order would be maintained.
The same effect could be attained with decimals too.
Those seem like very hacky, short-sighted solutions though.
Surely there's a "right way" to do this?