Search code examples
databasesqliteauto-increment

SQLite: Autoincrementing an Id to increase by 2


I was previously using SQL CE and have decided to move over to SQLite.

With that being said, SQL CE allowed me to auto increment an id by 2.

Is this is possible with SQLite?


Solution

  • SQLite has no mechanism to do this automatically.

    But you can calculate the new ID manually while inserting:

    INSERT INTO MyTable(ID, Name, Number)
    VALUES((SELECT MAX(ID) + 2 FROM MyTable),
           'me', 42);