How to make a Unique field for each Foreign key?

Asked

Viewed 103 times

2

I am studying mysql and came across the following situation and would like to know if there is a solution structuring my tables to solve this. Assuming I have two tables; user (id, user, password) and annotations(id, title, text, id_user). In the table annotations 'id_usuario' is a Foreign key. I would like the contents of the 'title' field of the 'annotations' table to be unique for each Foreign key. Thanks in advance!

1 answer

5


If it is via command just use this command to add a Constraint compound:

ALTER TABLE Persons
    ADD CONSTRAINT UC_Person UNIQUE (ID,LastName);

If it were via SGBD just edit the table, select the fields and mark the option Única (Unique).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.