Primary key in the associative table (Many for many)

3

Good evening.

I have the following question in the N relationship for N. The foreign keys become a composite primary key of the associative table. Correct?

Does this ensure that there is no repetition between tuples? Because I think even if they are composing the primary key there may be repetition, so I suppose in adding another primary key field to ensure integrity (func_projectID). Or is my thinking wrong?

Thanks for reading. Greetings.

    
asked by anonymous 07.01.2017 / 00:12

2 answers

2

In theory, your thinking is totally correct. In practice, only partially.

What you see in practice (which is a bit disappointing) is that developers ignore the creation of the key composed of implementation issues.

But with respect to the idea of the primary key preceding the other two columns is very common to observe.

It would look something like this:

pk func_project_id

fk func_id

fk func_project

To conclude, adding a primary key in the associative table is a cool and common idea to find in most software.

    
07.01.2017 / 01:44
2
  

I have the following question in relationship N for N. The keys   foreign keys become a composite primary key of the table   associative. Correct?

Correct. Relationships N to N must generate their own table that will have a relationship 1 to N with each one of them. The primary key of this table will consist of the primary keys of the tables that generated this new one.

  

Does this ensure that there is no repetition between tuples?

Yes, there will be no repetition between tuples, as the key will be composed of the primary keys of each of the tables, and by definition the keys are unique.

Below is an image of a slide that my teacher used to teach. I think that illustrates well.

NOTE : My answer is academic based and not practical. I have not yet had the opportunity to work on a real system.

    
07.01.2017 / 02:38