Bill Greer Bill Greer - 2 years ago 133
SQL Question

How to create an auto increment primary key in SQLite

I have the following create statement for a SQLite database table. What do I add to this statement to make the ID column auto-increment?

CREATE TABLE [Employee] ([Id] bigint NOT NULL , [FirstName] varchar(2147483647) NULL , [LastName] nvarchar(2147483647) NULL, [StartDate] Datetime NULL, [TermDate] datetime NULL, CONSTRAINT [sqlite_master_PK_Employee] PRIMARY KEY ([Id]));

Answer Source

You would use the autoincrement keyword:

    Id integer primary key autoincrement,
    . . .

However, you might want to review the documentation to see if this is really necessary. SQLite includes a rowid which often has sufficient functionality.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download