将一个主键设置为多个表的外键的任何简单方法

Any simple way to set one primary key as a foreign key to multiple tables

我有一个table

program(p_id(pk), program_name)

和另外三个 table:

graduate_survey(id(pk),PO1_avg,PO2_avg,program_name,session)

alumni_survey(id(pk),PO1_avg,PO2_avg,program_name,session),

faculty_survey(id(pk),PO1_avg,PO2_avg,program_name,session)...

我必须 link 三个 table 程序 table...如何 link table MySQL 中的这些 table ]? graduate_survey, alumni_survey, faculty_survey 是一些针对特定程序计算的形式...如果在形式 graduate_survey, alumni_survey, faculty_survey 中没有文本框用于输入 program_name,但是如果我在数据库 table 中创建了一个列名 'program_name',我可以通过引用 program table?是否会有任何连接查询?

在其他表中使用程序id作为外键,例如:

program(p_id(pk), program_name)
graduate_survey(id(pk),PO1_avg,PO2_avg,p_id(fk),session), 
alumni_survey(id(pk),PO1_avg,PO2_avg,p_id(fk),session), 
faculty_survey(id(pk),PO1_avg,PO2_avg,p_id(fk),session)

由于 FK 限制,您实际上并不需要程序名称,但在某些时候它仍然是一个很好的选择,也许。

这样就可以很方便的根据p_id加入,例如:

"SELECT * FROM program INNER JOIN graduate_survey ON program.p_id=graduate_survey.p_id WHERE <your condition here>"

希望对您有所帮助。