[Pgsql-ayuda] Respondiendo a Okeona;-p:

Rosa Vargas Urbina rvargas@correo.cnart.mx
Thu, 29 Jan 2004 19:01:43 -0600


Respondiendo a Okeona;-p:

<Hola a todos!

<Tengo problemas para crear FOREIGN KEY, me da un error y no se a que se
<refiere. Podría ser que no la creara bien. La cree:
<CREATE TABLE table_name(
<...
<CONSTRAINT constraint_name FOREIGN KEY(campo1,campo2) REFERENCES
<ref_table(ref_campo1,ref_campo2));
<*campo1 y campo2 son las únicas claves primarias de esta tabla.
<*ref_campo1 y ref_campo2 son claves primarias de ref_table, pero hay otra
<más en está tabla(ref_table)

<El error:

<ERROR: UNIQUE constraint matching give keys for referenced table
"ref_table"
not found.

Pues bien  yo lo hago de la siguiente manera, por ejemplo :


CREATE TABLE modalidad (
id                                  int                     NOT NULL ,
nombre                              varchar (30)            NOT NULL,
abrev                               char (3)                NOT NULL,
descripcion                         text                    NULL,
PRIMARY KEY   (id)

);



CREATE TABLE aspirante (
id                           serial,
ap_paterno                   varchar(40)       NOT NULL,
ap_materno                   varchar(40)       NOT NULL,
nombre1                      varchar(30)       NOT NULL,
PRIMARY KEY   (id)
);





El siguinete texto  tiene dos  llaves foraneas de  las
tablas:aspirante,modalidad, domicilio.

CREATE TABLE datosb_aspirante (
id                                serial ,
aspirante_id                      int4       NOT NULL REFERENCES
aspirante(id),
modalidad_id                      int        NOT NULL REFERENCES
modalidad(id),
PRIMARY KEY   (id)
);



PD: Como los id's son de tipo serial entonces se deben generar permisos
sobre estos campos
GRANT ALL ON aspirante_id_seq                  TO apache;
GRANT ALL ON domicilio_aspirante_id_seq        TO apache;
GRANT ALL ON datosb_aspirante_id_seq            TO apache;



Ojala te haya podido ayudar!
Saludos
Rosa Vargas