B4J Question [Solved] SQLite Autoincrement Problem

behnam_tr

Active Member
Licensed User
Longtime User
hi guys,


I have a database table that has a field called ID and the field is autoincrement.
Suppose it has 5 records whose IDs are from 1 to 5 respectively
Now I insert a record manually with ID 10
Next time when inserting a new record, it will automatically insert the number 11
I want to continue from number 6 for new recods. Is there a solution??

sorry for my bad english!
-------------------------
database :
tbl1 >> id,name

records :
1,"any name"
2,"any name"
3,"any name"
4,"any name"
5,"any name"
10,"any name"
------------------------
 
Solution
I don't really understand your problem. What does this have to do with the ID? The ID is just an internal marker for the database itself. How do you establish the relationship between the ID and the product code? The two have nothing to do with each other...
It doesn't really matter what ID the data record of a product code has, the important thing is the product code itself. Or are you using the ID as the product code? In my opinion, that would be a design error in the SQL database.
You search the SQL database using queries. There, too, the ID of a data record only plays a subordinate role. It does not belong to the actual data record. Why search for the product code via the IDs?
Please try to explain your problem to me a little...

MicroDrie

Well-Known Member
Licensed User
Anyone care to check this?
With 🤔 the risk of damaging the whole database with a corrupt sqlite_sequence table 😱 when inserting after the gap? 😅😂🤣
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
damaging the whole database with a corrupt sqlite_sequence table
Very wise of you to stay away from tampering with the sqlite_sequence table. The docs I read about it discourage manipulating it, in particular the docs from the official sqlite web site: Here is an excerpt:
'making modifications to this table will likely perturb the AUTOINCREMENT key generation algorithm. Make sure you know what you are doing before you undertake such changes'
 
Upvote 0
Top