MicrolearnENPTES

CREATE TABLE

Lesson 21 of 24 · SQL.Micro

Tables are defined once with their columns and types. A primary key identifies each row; a foreign key points to another table.

CREATE TABLE reviews (id INTEGER PRIMARY KEY, movie_id INTEGER REFERENCES movies(id), stars INTEGER);

Constraints like NOT NULL and CHECK (stars BETWEEN 1 AND 5) protect the data.

Check yourself

What does a primary key guarantee?

Create a table reviews with columns id (integer primary key), movie_id (integer, pointing to movies) and stars (integer), in that order.

Do it in the browser: a real SQL tool, a short mission and instant feedback. No install.

Start this lesson — free
← Window functionsINSERT →

All lessons · SQL.Micro