Create Table documentation, version 10 - Examples - Mailing list pgsql-docs

From PG Doc comments form
Subject Create Table documentation, version 10 - Examples
Date
Msg-id 154187385114.26256.11224208082049880576@wrigleys.postgresql.org
Whole thread Raw
List pgsql-docs
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/10/sql-createtable.html
Description:

I feel there should be an example of creating a table with a foreign key,
since it is pretty common.
Here is a suggestion which follows the established "theme" in the present
documentation :

Define a foreign key constraint on the `did` column of the `distributors`
table, deletion of a record in the `distributors` table will fail if a
record in the `films` table is still referring it.

```SQL
CREATE TABLE films (
    code        char(5) CONSTRAINT firstkey PRIMARY KEY,
    title       varchar(40) NOT NULL,
    did         integer NOT NULL REFERENCES distributors (did) ON DELETE
RESTRICT,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute
);

CREATE TABLE distributors (
    did    integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
    name   varchar(40) NOT NULL CHECK (name <> '')
);
```

pgsql-docs by date:

Previous
From: PG Doc comments form
Date:
Subject: The 'replication' keyword
Next
From: Alexander Lakhin
Date:
Subject: A typo in release notes