Foreign key with 3 primary keys

1

Hi. I have this table with 3 primary keys and I need to reference it in another table. How?

I was going to just put an id of type int in the monthly fee table to be the only primary key. But each monthly fee must be unique to a contract and have only one record per month / year, so 3 as the primary key.

In the simplest model, I would bind the id that is the primary key to the other table and would create a foreign key, like: id_mensalidade REFERENCES mensalidade(id) . Right?

But how do I do this in this template?

Thanks, if not clear, I can edit the post.

Using MySQL.

    
asked by anonymous 05.07.2018 / 04:56

1 answer

2

To reference a composite primary key would look like this:

FOREIGN KEY (ax,bx,cx) REFERENCES tabela_origem(a,b,c)
    
05.07.2018 / 05:25