[Pgsql-ayuda] problemas con foreign key

Alvaro Herrera alvherre@dcc.uchile.cl
Fri, 30 Jan 2004 20:51:25 -0300


On Fri, Jan 30, 2004 at 06:06:26PM +0000, nuria montoya rodriguez wrote:

> 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)
> 
> ERROR: UNIQUE constraint matching give keys for referenced table 
> "ref_table" not found.

A ver ... el ref_table tienes UNIQUE ref_campo1 y UNIQUE ref_campo2?
Si ese es el caso, no se puede.  Lo que necesitas es
UNIQUE (ref_campo1, ref_campo2).

Claro que las otras dos restricciones por separado son mas fuertes que
una sola restriccion para los dos campos, pero ...

-- 
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"Before you were born your parents weren't as boring as they are now. They
got that way paying your bills, cleaning up your room and listening to you
tell them how idealistic you are."  -- Charles J. Sykes' advice to teenagers