felix001
felix001

Reputation: 16731

SQLite3 Creating ID's

I have a SQLite table that contains an id field.

sqlite> PRAGMA table_info('posts')
   ...> ;
0|id|integer|1||1
1|uuid|varchar(36)|1||0
2|title|varchar(150)|1||0

When I insert a new entry into the table what is the advised approach for the id column. Is there an auto increment option or do I need to get the last id number and increment by 1 ?

Thanks,

Upvotes: 0

Views: 57

Answers (1)

laalto
laalto

Reputation: 152877

Just insert a null value to the id column and an identifier will be generated for you - it is the PRIMARY KEY as indicated by the last 1 in the table info.

Further reading: http://www.sqlite.org/autoinc.html

Upvotes: 2

Related Questions