Re: two primairy key in one table ?
От | Alvaro Herrera |
---|---|
Тема | Re: two primairy key in one table ? |
Дата | |
Msg-id | Pine.LNX.4.44.0207051204540.2200-100000@cm-lcon-46-187.cm.vtr.net обсуждение исходный текст |
Ответ на | two primairy key in one table ? (Angela Luyf <a.c.luyf@amc.uva.nl>) |
Список | pgsql-general |
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"
В списке pgsql-general по дате отправления: