如何插入指向许多ID的记录?

时间:2018-01-18 14:28:03

标签: mysql foreign-keys relational-database

我对如何实现此表(仍在学习SQL)感到有点困惑。我希望关系中有2个表,但是与另一个表相关的列需要能够接收MULTIPLE外键。以下是我想尝试做的例子......

**Candidate Table**
(PK) id : int
(FK) exams : ??? <------ Multiple students many have multiple exams, so I need this column to contain MULTIPLE foreign keys. WHAT is the datatype that needs to be assigned to this column to take multiple foreign ids???
candidate_name : varchar (50)

**Exams Table**
(PK) id : int
exam subject : varchar (50)
exam_no : varchar(10)
nom_candidates : int

在mySQL中执行此操作是否可行(即使它是一个混乱和混乱)?为获取多个键,第一个表中指向的列的数据类型是什么?

1 个答案:

答案 0 :(得分:0)

调查多对多关系。 Here is a good example.

  Map m = Collections.synchronizedMap(new HashMap());
      ...
  Set s = m.keySet();  // Needn't be in synchronized block
      ...
  synchronized (m) {  // Synchronizing on m, not s!
      Iterator i = s.iterator(); // Must be in synchronized block
      while (i.hasNext())
          foo(i.next());
  }