6

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]));
Bill Greer
  • 3,046
  • 9
  • 49
  • 80

1 Answers1

17

You would use the autoincrement keyword:

CREATE TABLE Employee (
    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.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786