Luís Tiago
Luís Tiago

Reputation: 143

SQL FOREIGN KEY's

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.

Upvotes: 0

Views: 51

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269773

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);

Upvotes: 3

Related Questions