We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Auto Increment

Many dialects of SQL support an AUTO INCREMENT feature. When inserting records into a table with AUTO INCREMENT enabled, the database will assign the next value automatically. In SQLite, an integer id field that has the PRIMARY KEY constraint will auto-increment by default!

IDs

Depending on how your database is set up, you may be using traditional ids or you may be using UUIDs. SQL doesn't support auto-incrementing a uuid, so if your database is using them your server will have to handle the changing uuids for each record.

Using AUTO INCREMENT in SQLite

We are using traditional ids in our database, so we can take advantage of the auto-increment feature. Different dialects of SQL will implement this feature differently, but in SQLite any column that has the INTEGER PRIMARY KEY constraint will auto-increment! So we can omit the id field within the INSERT statement and allow the database to automatically add that field for us!

Assignment

Let's add some more records into our users table, but allow the database to automatically increment the id field. Add the following records to the database:

Record 1

Record 2