title: How can I join two tables with two different primary keys into another table?
body: <p>I have two tables: <code>students</code> and <code>courses</code>, assuming that each student can be in more than one course and that each course can have more than one student.</p>
  
  <pre><code>[Table Students]             [Table Courses]
  id(PK)                       id(PK)
  name                         name
  age                          duration
  etc...                       etc...
  </code></pre>
  
  <p>and what I want to do it is to relate both tables into another table, for example, <code>studying</code>, in which I will store the course or courses that is doing each student. Like this:</p>
  
  <pre><code>[Table studying]
  idStudent
  idCourse
  </code></pre>
  
  <p><strong><em>What I have deduced</em></strong></p>
  
  <p>I think that <code>idStudent</code> and <code>idCourse</code> should be foreign keys because the information it is stored in <code>students</code> and <code>courses</code> respectively with an unique primary key and to respect the consistency of the database. It cannot exist a relation without information neither of the student nor the course or just without the information of one of them.</p>
  
  <p>I also know that some tables has two primary keys to allow that in the table could exist more than one repeated value of a primary key, but not of both primary keys at the same time.</p>
  
  <p><strong><em>My questions</em></strong></p>
  
  <ul>
  <li>These ids (<code>idStudent</code>, <code>idCourse</code>). Have to be primary keys or foreign keys?</li>
  <li>Should the table <code>studying</code> has another column with an ID?</li>
  <li>Is my deduction in the good way?</li>
  </ul>
  
  <p><strong>P.S:</strong> I do not need sql statements, I just need help to clarify my confusion.</p>
  
  <p>Thanks in advance!</p>