将上述表进行主键关联
时间: 2023-09-06 13:10:36 浏览: 75
好的,以下是将上述表进行主键关联的代码:
1. 员工表和部门表的关联:
```
ALTER TABLE employee ADD CONSTRAINT FK_employee_dept FOREIGN KEY (dept_id) REFERENCES department(id);
```
2. 员工表和职位表的关联:
```
ALTER TABLE employee ADD CONSTRAINT FK_employee_job FOREIGN KEY (job_id) REFERENCES job(id);
```
3. 部门表和员工表的关联:
```
ALTER TABLE department ADD CONSTRAINT FK_department_manager FOREIGN KEY (manager_id) REFERENCES employee(id);
```
4. 工资表和员工表的关联:
```
ALTER TABLE salary ADD CONSTRAINT FK_salary_employee FOREIGN KEY (employee_id) REFERENCES employee(id);
```
5. 考勤表和员工表的关联:
```
ALTER TABLE attendance ADD CONSTRAINT FK_attendance_employee FOREIGN KEY (employee_id) REFERENCES employee(id);
```
这样,我们就完成了对上述表的主键关联。主键关联可以保证表之间的数据一致性和完整性,避免不必要的数据冗余和错误。
阅读全文