What do you do if your data needs to have a defined order? The database itself does not guarantee the order of records unless you explicitly use an ORDER BY
clause.
However, you can always use a numeric field to define the order in which the items should be displayed. To avoid duplicate positions, use a UNIQUE
constraint on that field.
In the example below, the database stores music albums. Each song on an album has its position that can be set in the seq field of the album_song
table.
Note that the unique constraint is more complicated here. It needs to be applied within each album and not on the seq column itself.