Jump to content
Hi - you can't do that in most databases, unfortunately, although there are good reasons for this. ID numbers are usually set up to be completely unique and, uhm, what's the right word... Immutable? The idea is that you need a way to uniquely and completely foolproofly a database entry. If you would allow an entry with id number 3 to have a certain value, and then later on insert another entry with this same id number it could lead to uncertainties.
But is there really a problem? When you do a query on the database, you get a nice ordered list as a result, without "gaps". If needed you can sort by date created, if you add a column for date created.
If this still doesn't work for you, you need to update the database table everytime you delete an entry, with your own code, to set the values correctly in a sort of ID column.
But the "real" basic ID column is impossible to change in most databases, in order to be able to completely uniquely address a row entry.
I think I'd like to add to this in that it helps to understand the basic concept of MVC or Model-View-Controller. It can be some confusing terms, but to simplify things, the "Model" is the database or database table. It's your data, how it's defined. Then you have the view, or how the data is displayed. The controller is the glue in the middle.
How it's important here is if you want to display sequential numbers, you do that as part of the view. Let's say you're using a widget.newTableView() to show the data, when you insert the rows into the tableView you can give that row a number that's not tied to the database's unique ID. It could be something like:
View No Database ID No Description 1 1 Record #1 2 2 Record #2 3 4 Record #4 (3 was deleted) 4 7 Record #7, but 4th in the view
The database ID's don't need to map 1:1 to the numbers you might show in the view if you don't want it to appear to have gaps.
Community Forum Software by IP.Board