Search code examples
sqliteauto-increment

Autoincrement in SQLite tables


I create a table, lets name it CUSTOMERS in SQLite:

CREATE TABLE "CUSTOMERS" (
    "tel" INTEGER NOT NULL, 
    "customer" VARCHAR ,
);

When I see the table from a GUI (I use SQLite Manager from Firefox), I noticed that there is an extra column rowid which is working like auto-increment. My question is, in tables where I don't use a primary key should I specify a column like:

ROWID INTEGER PRIMARY KEY AUTOINCREMENT

If I execute this query PRAGMA table_info(CUSTOMERS); I get only the two columns tel,customer.


Solution

  • You can see here, as it was commented in your question.

    However, if you are in a dilemma what to choose between these options, SQLite recommends that you should not use AUTOINCREMENT attribute because:

    The AUTOINCREMENT keyword imposes extra CPU, memory, disk space, and disk I/O overhead and should be avoided if not strictly needed. It is usually not needed.

    More info you can read here.