Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 905AD1337B82 for ; Fri, 6 May 2011 22:50:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 38639-06 for ; Sat, 7 May 2011 01:50:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iy0-f174.google.com (mail-iy0-f174.google.com [209.85.210.174]) by mail.postgresql.org (Postfix) with ESMTP id 5F31E1337B67 for ; Fri, 6 May 2011 22:50:06 -0300 (ADT) Received: by iyb14 with SMTP id 14so3085019iyb.19 for ; Fri, 06 May 2011 18:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=+L+LF3RSMQW8JYkN8vVuQejQybJ1Y1Y+ewzOWDSu3hM=; b=k27VCfFp9lIj/0bi7BfiKywCVWE9O2m6OLYIVrNuMx6kRk1Z1Icgtsxz6DULPtyOI8 yMhA2yxaOqJV1ECNaBEzJVt3ACgg489k3iwlZcuJAkGP6VSb+6vptFbxn2m3vdQazxxK 7SAVLnAuUSOUOT9LOIGOKwChF8eFfexXwXGbU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=VZ/JZ1WKEVW/YVAwqE/lUNXCQkxAjhRHqftCWb5zzIZA6oNSJWiQt0tJC2EdhXpKqH lrAaFO9BeZCeDyf3ToSFXIjSwLpLZKr9uiK5Orcmw0sA6gMu3YeitZnttSkkfb16brX7 NhYbASeLXF77mHYbstyyysLlkBf4dfiT0RAso= MIME-Version: 1.0 Received: by 10.231.23.65 with SMTP id q1mr1771598ibb.74.1304733007095; Fri, 06 May 2011 18:50:07 -0700 (PDT) Received: by 10.231.12.131 with HTTP; Fri, 6 May 2011 18:50:07 -0700 (PDT) Date: Sat, 7 May 2011 03:50:07 +0200 Message-ID: Subject: 5.3.5. Foreign Keys (The SQL Language) possible enhance From: Grzegorz Szpetkowski To: pgsql-docs@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.888 tagged_above=-5 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, RFC_ABUSE_POST=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201105/26 X-Sequence-Number: 6701 I have some remark about "Now it is impossible to create orders with product_no entries that do not appear in the products table." http://www.postgresql.org/docs/9.0/static/ddl-constraints.html#DDL-CONSTRAINTS-FK Let' see: CREATE TABLE products ( product_no integer PRIMARY KEY, name text, price numeric ); CREATE TABLE orders ( order_id integer PRIMARY KEY, product_no integer REFERENCES products (product_no), quantity integer ); INSERT INTO products VALUES (1, 'Bosch vacuum cleaner', 10); INSERT INTO orders VALUES (1, 1, 1); INSERT INTO orders VALUES (2, NULL, 5); There is still possibility to add product_no (exactly NULL) value, which does not appear (cannot because of primary key nature) in products table. To get "full solution" you need create orders table as CREATE TABLE orders ( order_id integer PRIMARY KEY, product_no integer REFERENCES products (product_no) NOT NULL, quantity integer ); Regards, Grzegorz Szpetkowski