From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Charles Hauser <chauser@duke.edu>
Cc: PSQL_list <pgsql-sql@postgresql.org>
Subject: Re: Use of reference table ('look-up-table') and FK constraint
Date: Wed, 16 Oct 2002 10:26:22 -0700 (PDT)
Message-ID: <20021016102409.C96229-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <1034788500.414.63.camel@pandorina.biology.duke.edu>
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
);
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: pgsql-sql@postgresql.org
Cc: sszabo@megazone23.bigpanda.com, chauser@duke.edu
Subject: Re: Use of reference table ('look-up-table') and FK constraint
In-Reply-To: <20021016102409.C96229-100000@megazone23.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox