[Pgsql-ayuda] Como implementar triggers con Pl/PgSQL.

Odiel León odiel@jagua.cfg.sld.cu
Wed, 16 Jul 2003 18:02:23 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_00A9_01C34BC4.68B213C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Para el primer caso puedes usar esto.

CREATE TABLE products (
    product_no integer PRIMARY KEY,
    name text,
    price numeric
);

CREATE TABLE orders (
    order_id integer REFERENCES product_no ON DELETE CASCADE,
    shipping_address text,
    ...
);

Cuando borres cualquier elemento de la tabla products automaticamente se =
borrara de la hija.


... PostgreSQL\usr\doc\postgresql-7.3.1\html\ddl-constraints.html

Salu2.
Odiel.


  ----- Original Message -----=20
  From: Josue Maldonado=20
  To: pgsql-ayuda@tlali.iztacala.unam.mx=20
  Sent: Friday, July 11, 2003 6:52 PM
  Subject: [Pgsql-ayuda] Como implementar triggers con Pl/PgSQL.


  Hola lista,
  =20
  Disculpenme si mi inquietud parece muy simple o torpe. He revisado la =
ayuda de postgre y no he podido encontrar un ejemplo de como hacer con =
Pl/PgSql lo siguiente.
  =20
  1. Un trigger que se ejecute cuando borro el registro de una tabla =
padre para que la integridad referencial pueda borrar los registros de =
la tabla hija.
  =20
  2. Un trigger que inserte o actualize registros en otra tabla cuando =
se inserten o modifiquen registros en la tabla padre.
  =20
  De antemano muchas gracias
  =20
  Josu=E9 Maldonado.

------=_NextPart_000_00A9_01C34BC4.68B213C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Para el primer caso puedes usar =
esto.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>CREATE TABLE products =
(<BR>&nbsp;&nbsp;&nbsp;=20
product_no integer PRIMARY KEY,<BR>&nbsp;&nbsp;&nbsp; name=20
text,<BR>&nbsp;&nbsp;&nbsp; price numeric<BR>);<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>CREATE TABLE orders =
(<BR>&nbsp;&nbsp;&nbsp;=20
order_id integer REFERENCES&nbsp;product_no <B class=3DEMPHASIS>ON =
DELETE=20
CASCADE</B>,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; shipping_address=20
text,<BR>&nbsp;&nbsp;&nbsp; ...<BR>);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Cuando borres cualquier elemento de la =
tabla=20
products automaticamente se borrara de la hija.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>...=20
PostgreSQL\usr\doc\postgresql-7.3.1\html\ddl-constraints.html</FONT></DIV=
>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Salu2.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Odiel.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><BR>&nbsp;</DIV></FONT>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A href=3D"mailto:josue@lamundial.hn" title=3Djosue@lamundial.hn>Josue =

  Maldonado</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A=20
  href=3D"mailto:pgsql-ayuda@tlali.iztacala.unam.mx"=20
  =
title=3Dpgsql-ayuda@tlali.iztacala.unam.mx>pgsql-ayuda@tlali.iztacala.una=
m.mx</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, July 11, 2003 =
6:52 PM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> [Pgsql-ayuda] Como =
implementar=20
  triggers con Pl/PgSQL.</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>Hola lista,</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Disculpenme si mi inquietud parece =
muy simple o=20
  torpe. He revisado la ayuda de postgre y no he podido encontrar un =
ejemplo de=20
  como hacer con Pl/PgSql lo siguiente.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>1. Un trigger que se ejecute cuando =
borro el=20
  registro de una tabla padre para que la integridad referencial pueda =
borrar=20
  los registros de la tabla hija.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>2. Un trigger que inserte o=20
  actualize&nbsp;registros en otra tabla cuando se inserten o modifiquen =

  registros en la tabla padre.</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>De antemano muchas =
gracias</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Josu=E9=20
Maldonado.</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_00A9_01C34BC4.68B213C0--