pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
constrains problem...
2+ messages / 2 participants
[nested] [flat]

* constrains problem...
@ 2005-12-07 12:38 Jure Kodzoman <jure@plsavez.hr>
  2005-12-07 18:57 ` Re: constrains problem... Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Jure Kodzoman @ 2005-12-07 12:38 UTC (permalink / raw)
  To: pgsql-sql

Hy list, i would like to ask you for help.



 I have 3 tables. 


table1 has primary key 't1code' and table_rel  is 'many to many'
relation 
for table2. 


table2 primary key is 't2code'


table_rel has two fields: 't1code' and 't2code', where both of them 
together make a primary key for the relation table. This is done so no
double values exist.


What i would like to do is create a trigger or a constraint which would 
on delete of an entry from table1 also deleted all entries containing
code from 
table1 in table_rel. When i try to put a constraint via PgAdmin3 it says
it can't do 
it because 't1code' is not primary key or unique. 

I understand the error, but what i would like to know is how to delete 
all fields from table_rel containing the 'table1' vaule being equal to 
'code' being deleted from table1. 


Thanks a lot for your anwser! 


Yure 





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: constrains problem...
  2005-12-07 12:38 constrains problem... Jure Kodzoman <jure@plsavez.hr>
@ 2005-12-07 18:57 ` Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2005-12-07 18:57 UTC (permalink / raw)
  To: Jure Kodzoman <jure@plsavez.hr>; +Cc: pgsql-sql

Jure Kodzoman wrote:
> What i would like to do is create a trigger or a constraint which would 
> on delete of an entry from table1 also deleted all entries containing
> code from 
> table1 in table_rel. When i try to put a constraint via PgAdmin3 it says
> it can't do 
> it because 't1code' is not primary key or unique. 
> 
> I understand the error, but what i would like to know is how to delete 
> all fields from table_rel containing the 'table1' vaule being equal to 
> 'code' being deleted from table1. 

You put two foreign keys ON table_rel, referencing table1 and table2. 
Set both to delete on cascade and you're done.

-- 
   Richard Huxton
   Archonet Ltd



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-12-07 18:57 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-12-07 12:38 constrains problem... Jure Kodzoman <jure@plsavez.hr>
2005-12-07 18:57 ` Richard Huxton <dev@archonet.com>

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