pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Tutorial : using foreign keys, retrictions etc
3+ messages / 3 participants
[nested] [flat]

* Tutorial : using foreign keys, retrictions etc
@ 2001-06-02 22:49  Mario Bittencourt <mneto@argo.com.br>
  0 siblings, 2 replies; 3+ messages in thread

From: Mario Bittencourt @ 2001-06-02 22:49 UTC (permalink / raw)
  To: pgsql-sql

Hi,

        I've decided to switch from mysql to postgresql as my database server. I 
do mostly web programming (who doesnt these days?) with more than a 100 
sites developed (using mysql).

        I've read about postgresql and it's features (such as triggers, stored 
procedures, views) and I'd like to know if there is some tutorial/snippet 
of code regarding such features specially  the use of foreign keys and 
referetial integrity.

        To give a more concrete example the next app I'd like to use postgresql 
needs this behaviour :

table A
id,  name

table B
id, foo

table C
id, date

        If I change id in table A update table B to change it too (I think it's 
called cascade).

        Thanks.

- RM
        



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

* Re: Tutorial : using foreign keys, retrictions etc
@ 2001-06-06 15:41  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Mario Bittencourt <mneto@argo.com.br>
  1 sibling, 0 replies; 3+ messages in thread

From: Stephan Szabo @ 2001-06-06 15:41 UTC (permalink / raw)
  To: Mario Bittencourt <mneto@argo.com.br>; +Cc: pgsql-sql

On Sat, 2 Jun 2001, Mario Bittencourt wrote:

> Hi,
> 
>         I've decided to switch from mysql to postgresql as my database server. I 
> do mostly web programming (who doesnt these days?) with more than a 100 
> sites developed (using mysql).
> 
>         I've read about postgresql and it's features (such as triggers, stored 
> procedures, views) and I'd like to know if there is some tutorial/snippet 
> of code regarding such features specially  the use of foreign keys and 
> referetial integrity.
> 
>         To give a more concrete example the next app I'd like to use postgresql 
> needs this behaviour :
> 
> table A
> id,  name
> 
> table B
> id, foo
> 
> table C
> id, date
> 
>         If I change id in table A update table B to change it too (I think it's 
> called cascade).

In this case it's pretty easy, 
table B needs a foreign key defined like:
 FOREIGN KEY (id) REFERENCES A(id) ON UPDATE CASCADE
(you may want ON DELETE CASCADE as well, it depends).

I believe someone had written a document on FK, but I'm not entirely sure
what happened to it or whether it ended up in the docs.  For examples
without much explanation you can look at the foreign key regression test,
but that's not alot of help.





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

* Re: Tutorial : using foreign keys, retrictions etc
@ 2001-06-06 17:03  Roberto Mello <rmello@cc.usu.edu>
  parent: Mario Bittencourt <mneto@argo.com.br>
  1 sibling, 0 replies; 3+ messages in thread

From: Roberto Mello @ 2001-06-06 17:03 UTC (permalink / raw)
  To: Mario Bittencourt <mneto@argo.com.br>; +Cc: pgsql-sql

On Sat, Jun 02, 2001 at 06:49:55PM -0400, Mario Bittencourt wrote:
> Hi,
> 
>         I've decided to switch from mysql to postgresql as my database server.

	Good for you :)

> procedures, views) and I'd like to know if there is some tutorial/snippet 
> of code regarding such features specially  the use of foreign keys and 
> referetial integrity.

	You might want to look at http://techdocs.postgresql.org. 
	IIRC, a script to "port" MySQL code to PostgreSQL has been included in
the contrib section of 7.1.x.
	For examples of functions, head to http://www.brasileiro.net/postgres

	-Roberto
-- 
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
  Roberto Mello - Computer Science, USU - http://www.brasileiro.net 
       http://www.sdl.usu.edu - Space Dynamics Lab, Developer    
Bad command or file name. Go sit in corner.



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


end of thread, other threads:[~2001-06-06 17:03 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-02 22:49 Tutorial : using foreign keys, retrictions etc Mario Bittencourt <mneto@argo.com.br>
2001-06-06 15:41 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-06-06 17:03 ` Roberto Mello <rmello@cc.usu.edu>

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