Create Table documentation, version 10 - Examples

Поиск
Список
Период
Сортировка
От PG Doc comments form
Тема Create Table documentation, version 10 - Examples
Дата
Msg-id 154187385114.26256.11224208082049880576@wrigleys.postgresql.org
обсуждение исходный текст
Список 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 по дате отправления:

Предыдущее
От: PG Doc comments form
Дата:
Сообщение: The 'replication' keyword
Следующее
От: Alexander Lakhin
Дата:
Сообщение: A typo in release notes