That's a good question.
You will notice a limitation FOREIGN KEYin the doc examples related to DDL constraints. I prefer to use the restriction FOREIGN KEYas indicated in example 3. below.
/ -:
CREATE TABLE products (
product_no integer PRIMARY KEY,
name text,
price numeric
);
- Ex1
FOREIGN KEY
CREATE TABLE orders (
order_id integer PRIMARY KEY,
product_no integer REFERENCES products (product_no),
quantity integer
);
- Ex2
, .
CREATE TABLE orders (
order_id integer PRIMARY KEY,
product_no integer REFERENCES products,
quantity integer
);
- Ex3
, FOREIGN KEY.
CREATE TABLE orders (
order_id integer PRIMARY KEY,
product_no integer,
quantity integer,
FOREIGN KEY (product_no) REFERENCES products (product_no),
);
, , FOREIGN KEY :
CREATE TABLE t1 (
a integer PRIMARY KEY,
b integer,
c integer,
FOREIGN KEY (b, c) REFERENCES other_table (c1, c2)
);
.
SQL: http://sqlfiddle.com/#!15/dd2d6