Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A6133476002 for ; Wed, 16 Oct 2002 13:26:28 -0400 (EDT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 365F6475F1B for ; Wed, 16 Oct 2002 13:26:28 -0400 (EDT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 1BFAAD609; Wed, 16 Oct 2002 10:26:22 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id DD8915C02; Wed, 16 Oct 2002 10:26:22 -0700 (PDT) Date: Wed, 16 Oct 2002 10:26:22 -0700 (PDT) From: Stephan Szabo To: Charles Hauser Cc: PSQL_list Subject: Re: Use of reference table ('look-up-table') and FK constraint In-Reply-To: <1034788500.414.63.camel@pandorina.biology.duke.edu> Message-ID: <20021016102409.C96229-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/179 X-Sequence-Number: 9896 On 16 Oct 2002, Charles Hauser wrote: > In fits and starts I am working through converting a sybase schema -> > postgres and am hoping to gain some insight on the use of reference > tables ('look-up-table') and FK constraints. > > In the example below I believe the sybase RULE Phone_type_rule is used > to restrict input, so that the only values which can be inserted or > updated into Phone have to be one of ('work', 'home', 'fax', 'mobile', > 'lab', 'unknown'). > > How would this be accomplished using a look-up or reference table::FK > constraint combination? > > CREATE RULE Phone_type_rule > AS @col IN ('work', 'home', 'fax', 'mobile', 'lab', 'unknown') > go > > CREATE TABLE Phone ( > phone_id Identifier_type IDENTITY, > phone_number varchar(20) NOT NULL, > community_id numeric(12) NOT NULL, > type varchar(10) NULL > ) I think something like this: create table phone_types ( typename varchar(10) primary key; ); -- insert types into phone_types create table phone( -- ... type varchar(10) references phone_types );