Database DesignSQL basicsLesson 25 / 69

CREATE & INSERT

Code Lab30 min

CREATE & INSERT

SQL is small enough to say aloud. You make tables and fill them:

CREATE TABLE authors (
  id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name varchar(100) NOT NULL
);

INSERT INTO authors (name) VALUES ('Margaret'), ('Toni');

GENERATED ALWAYS AS IDENTITY means the database numbers rows for you — never supply id yourself. And NOT NULL is your first integrity tool: the insert fails loudly instead of storing a lie.

Exercise

Create tables for authors and books (books reference authors). Insert two authors and three books, at least one per author.

Practice this lesson in the IDE

Open the Database Design practice workspace, edit the starter code, and run your work in the browser.

Open IDE and practice