Looking for sql Answers? Try Ask4KnowledgeBase
Looking for sql Keywords? Try Ask4Keywords

SQL Using Auto Increment


Example

Many databases allow to make the primary key value automatically increment when a new key is added. This ensures that every key is different.

MySQL

CREATE TABLE Employees (
    Id int NOT NULL AUTO_INCREMENT,
    PRIMARY KEY (Id)
);

PostgreSQL

CREATE TABLE Employees (
    Id SERIAL PRIMARY KEY
);

SQL Server

CREATE TABLE Employees (
    Id int NOT NULL IDENTITY,
    PRIMARY KEY (Id)
);

SQLite

CREATE TABLE Employees (
    Id INTEGER PRIMARY KEY    
);