Restrictions for a specific situation in my DB

Поиск
Список
Период
Сортировка
От JORGE MALDONADO
Тема Restrictions for a specific situation in my DB
Дата
Msg-id CAAY=A79am3Cndk6DNPKA6Z0286YYxF9eYKWR=fUic-CEPjQntw@mail.gmail.com
обсуждение исходный текст
Ответы Re: Restrictions for a specific situation in my DB  (Bzzzz <lazyvirus@gmx.com>)
Re: Restrictions for a specific situation in my DB  (Bzzzz <lazyvirus@gmx.com>)
Re: Restrictions for a specific situation in my DB  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Restrictions for a specific situation in my DB  (Laurenz Albe <laurenz.albe@cybertec.at>)
Список pgsql-novice
Hi,

I have a table with the following structure:

------------------------------------------------------------------------------
FIELD       TYPE                         COMMENTS
------------------------------------------------------------------------------
    id            serial                 primary key
    m1          integer              id of record in another table
    m2          integer              id of record in another table

So, "m1" and "m2" are foreign keys.
I have read that it is a good practice to define an index for each foreign key so "m1" and "m2" are also regular and independent indexes.

Now, the combination of "m1" and "m2" together cannot be duplicated. So for example, the following entries 

---------------------------------------------------------------------
id             m1            m2           COMMENTS                   
---------------------------------------------------------------------
 1              2               10
 2              8                3
 3             18               1
 4              2               10           This is invalid.
 5             13               8            This is invalid.
 6             18              18           This is invalid.

Maybe the case for records 4 and 5 can be achieved by setting 2 restrictions:
Restriction 1: "m1 + m2" fields
Restriction 2: "m2 + m1" fields

But, is this a good approach?

Respectfully,
Jorge Maldonado



В списке pgsql-novice по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Unique Constraint vs Unique Index
Следующее
От: Bzzzz
Дата:
Сообщение: Re: Restrictions for a specific situation in my DB