public inbox for [email protected]
help / color / mirror / Atom feedFrom: PG Doc comments form <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Create Table documentation, version 10 - Examples
Date: Sat, 10 Nov 2018 18:17:31 +0000
Message-ID: <[email protected]> (raw)
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 <> '')
);
```
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Create Table documentation, version 10 - Examples
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox