我有一个包含此架构的数据库:
项目
ProjectId ProjName Costs PStart PFinish
Project(ProjectID, Integer, PKEY)
工作包
WorkpacketID WorkpacketName WStart WFinish
Workpacket (WorkpacketID,Integer,PKEY)
Workpacket got a FKEY ond ProjectID
员工
EmployeeID EmployeeName EmployeSalary
Employee (EmployeeID, Integer, PKEY)
Employee got a FKEY on ProjectID and WorkpacketID
现在我想选择 ProjectID 并获取以下信息: ProjectName,WorkpacketID,WorkpacketName,WStart 。
Select Project.ProjectID, Project.ProjectName, Workpacket.WorkpacketID,
Workpacket.WorkpacketName, Workpacket.WStart
from Project, Workpacket
where Project.ProjectID = 1;
这是对的吗?我不明白如何在这里使用连接,如果连接是FKEY的必要原因。
答案 0 :(得分:0)
要连接表,必须有一个键,在哪个基础上执行连接。
在您的项目表中,Projectid是关键
workpacked workpacketId中的是关键
员工员工ID中的是关键
但是每个表都没有关键字显示这3个表之间的关联
项目表应该有WorkpackedID,并且Workpacked应该有employeId来执行连接