web dev//SQL//DDL

Data Definition Language (DDL) is the subset of SQL that defines structure rather than data: `CREATE TABLE`, `ALTER TABLE`, `DROP TABLE`. It builds the container without filling it, and in a team it is written as schema migrations, versioned files applied in order to every environment. A table with 20 columns takes 42 clean lines, which makes SQL the best way to define big entities.


Data Definition Language (DDL) is the subset of SQL that defines structure rather than data: CREATE TABLE, ALTER TABLE, DROP TABLE. It builds the container without filling it, and in a team it is written as schema migrations, versioned files applied in order to every environment. A table with 20 columns takes 42 clean lines, which makes SQL the best way to define big entities.

The key constraints in a CREATE TABLE are these:

UUID PRIMARY KEY DEFAULT gen_random_uuid() gives each row a unique identifier, generated automatically when none is provided.

NOT NULL makes a field mandatory.

REFERENCES table(column) declares a foreign key that points to another table.

DEFAULT value sets a fallback value.

CHECK (col IN (...)) accepts only the listed values, like an enum.

UNIQUE (a, b) forbids the combination from repeating.

TEXT[] stores an array inside a column (PostgreSQL specific).

In Supabase, DDL is written in the SQL Editor rather than in the Table Editor. The Table Editor is for viewing and editing rows (spreadsheet mode); the SQL Editor can do everything, from triggers and indexes to RLS policies and complex queries, and it even saves queries as favorites. One is visual, the other is powerful.