Tables and data

Use identity primary keys

Create generated numeric identifiers with the SQL-standard identity syntax.

8 minute lesson

~~~

Define a generated key like this:

CREATE TABLE notes (
  id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  title TEXT NOT NULL
);

Identity columns use a sequence underneath but keep the generation rule attached to the column definition.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →