How to make a unique field for each foreign key?

1

I am studying mysql and I 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, userid). In the Annotations table 'id_user' is a foreign key. I would like the contents of the 'title' field of the 'anotacoes' table to be unique for each foreign key. Thank you in advance!

    
asked by anonymous 06.06.2018 / 18:13

1 answer

4

If this is a command, just use this command to add a constraint of a unique composite:

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

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

    
06.06.2018 / 18:18