Re: Creating related tables

From: "Kevin Crenshaw" <kcrenshaw(at)viscient(dot)com>
To: 'Ângelo Marcos Rigo' <angelo_rigo(at)yahoo(dot)com(dot)br>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Creating related tables
Date: 2005-10-19 13:23:51
Message-ID: 20051019132349.066F7DA29D@svr1.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Try:

CREATE TABLE owners (
Ownerid SERIAL PRIMARY KEY,
Ownername TEXT
);

CREATE TABLE motorcycles(
Mid SERIAL PRIMARY KEY,
Mname TEXT,
Ownerid INTEGER REFERENCES owners(ownerid)
ON DELETE CASCADE
);

HTH,

Kevin


-----Original Message-----
From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Ângelo Marcos Rigo
Sent: Wednesday, October 19, 2005 8:34 AM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] Creating related tables

Hi

I need to create 1:N related tables .

eg.: table A and a table B.
- table B will have motorcicles
- table A will have motorcicles owners
If a owner is deleted from the table A i need to
delete all the motorcicles with the deleted owner id
in the B table.

What is the sintax in postgesql todo this ?

Ângelo Marcos Rigo
AMR Informática
(51) 3348 0870
Rua Pe. Alois Kades 400/210
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo(at)yahoo(dot)com(dot)br



_______________________________________________________
Promoção Yahoo! Acesso Grátis: a cada hora navegada você acumula cupons e
concorre a mais de 500 prêmios! Participe! http://yahoo.fbiz.com.br/

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Cristian Prieto 2005-10-19 18:24:45 SQL return value...
Previous Message Michael Glaesemann 2005-10-19 13:09:53 Re: Creating related tables