如何id分配外键mysqli

时间:2016-02-04 09:18:16

标签: php mysql html5 mysqli

我在2张桌子上创建了。这些表是Department,employee。

现在我想在部门表中分配外键,并在员工表中分配加入

有什么想法??

SELECT id,department FROM department; 
SELECT * FROM `employee'

2 个答案:

答案 0 :(得分:3)

create employee table field are- id(primary key),name,dept_id
department table fields are-dept_id(primary key),name

选择dept_id.give索引后。 enter image description here

选择department表和dept_id.than单击“保存”按钮。 enter image description here

答案 1 :(得分:0)

你在找这个: -

$query="select emp.name, dep.department from employee emp 
INNER JOIN 
department dep ON 
emp.department=dep.department 
order by emp.name asc";
相关问题