views:

1818

answers:

1

Hi,

In my table I want to have an ID column that is going to be unique and it is going to be autoincremented. I want to start from 0.

How can I implement it?

+6  A: 

Basically, create a column of type INTEGER PRIMARY KEY or a column called ROWID, then don't specify the value when inserting a row.

Full details are on the SQLite page on Autoincrement.

andypaxo
I tried it, but in my table I am getting first id to be 2, not 0. Why is this happening?
Ilya
The linked page describes in detail the algorithm that is used to select new IDs. My guess is that you've previously had one or more rows added to the table.If not, I don't know.
andypaxo