JavaDB: Is it possible to change autogrowth change to existing table?
Is it possible to change the autoincrement offset in a pre-existing table using JavaDB?
I am having an issue where inserting new records usually (but not always) fails with an error related to using an existing key (my auto-incrementing column). To populate this database, I took a dump from another database (MySQL) and used a JavaDB stored procedure to insert them all into the corresponding JavaDB table. My theory is that inserting these records was copying existing ids from the MySQL table. The auto-increment functionality now displays existing IDs. I believe that explicitly specifying the offset to some large number will allow autoincrement to be activated again.
source to share
I don't know how to directly change the offset, but I managed to fix it:
- Changing the increment amount by X (1 million in my case).
- Insert dummy record.
- Reducing the number of increments to 1.
- Deleting a dummy entry.
I used this SQL statement to change the sum of the increments:
ALTER TABLE tbl ALTER COLUMN col SET INCREMENT BY x
source to share