From: | PG Doc comments form <noreply(at)postgresql(dot)org> |
---|---|
To: | pgsql-docs(at)lists(dot)postgresql(dot)org |
Cc: | jcd9930(at)hotmail(dot)ca |
Subject: | Create Table documentation, version 10 - Examples |
Date: | 2018-11-10 18:17:31 |
Message-ID: | 154187385114.26256.11224208082049880576@wrigleys.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 <> '')
);
```
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Lakhin | 2018-11-12 11:15:31 | A typo in release notes |
Previous Message | PG Doc comments form | 2018-11-10 06:08:22 | The 'replication' keyword |