Luís Tiago Luís Tiago - 1 year ago 110
SQL Question


How do prevent a table with 2 FOREIGN key's from having repeated rows with the same value.

enter image description here

Thks in advance.

Answer Source

Use a unique index or constraint:

alter table example
    add constraint unq_example_fk1_fk2 unique (fk1, fk2);

A unique constraint and unique index do essentially the same thing. So, you can also do:

create unique index unq_example_fk_fk on example(fk1, fk2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download