Thread: Forein Key

Forein Key

From
"Marcelo Pereira"
Date:
Hi,
 
I'm a new user and I would like to know if I can create my table using forein key's.
 
 
Thanks
 
Marcelo Pereira
Computer Programmer

Re: Forein Key

From
Frank Joerdens
Date:
On Fri, Mar 09, 2001 at 03:43:55PM -0300, Marcelo Pereira wrote:
>
>    Hi,
>
>
>
>    I'm a new user and I would like to know if I can create my table using
>    forein key's.

Sure. Here's an example:

test=> CREATE TABLE statename     (    code CHAR(2) PRIMARY KEY,
test(>                     name CHAR(30)
test(>                 );
CREATE
test=> INSERT INTO statename VALUES ('AL', 'Alabama');
INSERT 18934 1

test=> CREATE TABLE customer     (
test(>                 customer_id INTEGER,
test(>                 name CHAR(30),
test(>                 telephone CHAR(20),
test(>                 street CHAR(40),
test(>                 city CHAR(25),
test(>                 state CHAR(2) REFERENCES statename,
test(>                 zipcode CHAR(10),
test(>                 country CHAR(20)
test(>                 );
CREATE

(from Bruce Momjian's excellent book on PostgreSQL)

Regards, Frank