Bill Greer Bill Greer - 9 months ago 64
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]));


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.