Redo autoincrement in SQLite

1

I'm passing data from an old bank to a new bank. After executing all querys there were some primary key fields that were "missing". Example the id column jumped from die '11' to '13' since die '12' was deleted. This occurs in several cases in the bank. How do I completely erase the IDs and redo them to follow a correct order?

    
asked by anonymous 12.06.2016 / 22:34

1 answer

2

The question does not help much but I would try to do this in importing the data into the new table:

INSERT INTO novatabela (word, definicao, classe_gramatical)
    SELECT word, definicao, classe_gramatical FROM tabelaantiga

Leave without the word_id , so the numbering will be done from scratch. Make sure the table has just been created. If it is necessary to do this in a temporary table, delete the old one and rename the temporary one to replace the old one.

Stay tuned to the comments in the question because changing a primary key can have disastrous consequences for the database.

Depending on whether you have holes in ids is not usually a good idea. You will have to guarantee this, which is not easy. Again you have comments giving you a better solution.

Ideally you should not use AUTOINCREMENT for anything in SQLite .

    
12.06.2016 / 23:32