Ben Lewis Ben Lewis - 3 months ago 18
Android Question

Do you need both primary key AND autoincrement for creating table in SQLite?

Or can you just use one or the other? I'd like to avoid redundancy while ensuring uniqueness by just using PRIMARY KEY but am wondering whether the added rows will AUTOINCREMENT by default.

Answer

Yes, added rows will have automatically generated values for primary keys if you don't supply an explicit non-null value yourself. The algorithm for generating such values is slightly different with and without AUTOINCREMENT keyword.