Re: can a foreign key allow null

From: Steven Klassen <sklassen(at)commandprompt(dot)com>
To: Keith Worthington <keithw(at)narrowpathinc(dot)com>
Cc: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: can a foreign key allow null
Date: 2004-10-19 19:12:16
Message-ID: 20041019191216.GB31945@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

* Keith Worthington <keithw(at)narrowpathinc(dot)com> [2004-10-19 15:01:40 -0400]:

> Table "myschema.tbl_part"
> Column | Type | Modifiers
> ----------------------+------------------------+-----------
> sales_gl_account | character varying(15) |
>
> Table "myschema.tbl_gl_account"
> Column | Type | Modifiers
> -------------+-----------------------+-----------
> number | character varying(15) | not null
>
> Is it possible to create a foreign key such that only null and
> values from myschema.tbl_gl_account.number are allowed in
> myschema.tbl_part.sales_gl_account?

How is this any different than a regular foreign key constraint?

ALTER TABLE tbl_part ADD CONSTRAINT account_number_exists FOREIGN KEY
(sales_gl_account) REFERENCES tbl_gl_account(number);

HTH,

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Hari Bhanujan 2004-10-20 05:37:13 Re: Postgresql for Dummies?
Previous Message Keith Worthington 2004-10-19 19:01:40 can a foreign key allow null