Angela Luyf dijo:
> Hello,
> I have a database model where a many to many relation is used, so i need
> to create a table with two primary key. Don't know how to solve this in
> postgress, can't find it in the tutorials, so can anybody help me with
> this ?
CREATE TABLE twos (one INT, two INT, PRIMARY KEY (one, two));
But I don't think that's the solution for many-to-many relations.
Should be more like:
CREATE TABLE first (one SERIAL PRIMARY KEY);
CREATE TABLE second (two SERIAL PRIMARY KEY);
and the table with foreign constraints should be:
CREATE TABLE third (one INT REFERENCES first NOT NULL,
two INT REFERENCES first NOT NULL,
PRIMARY KEY (one, two)
);
BTW, this is in the "table_constraint" part of the grammar.
HTH,
--
Alvaro Herrera (<alvherre[a]atentus.com>)
"The ability to monopolize a planet is insignificant
next to the power of the source"