create table employee
(emp_id smallint unsigned not null auto_increment,
fname varchar(20) not null,
lname varchar(20) not null,
start_date date not null,
end_date date,
superior_emp_id smallint unsigned,
dept_id smallint unsigned,
title varchar(20),
assigned_branch_id smallint unsigned,
constraint fk_e_emp_id
foreign key (superior_emp_id) references employee (emp_id),
constraint fk_dept_id
foreign key (dept_id) references department (dept_id),
constraint fk_e_branch_id
foreign key (assigned_branch_id) references branch (branch_id),
constraint pk_employee primary key (emp_id)
);
나는이 Example을 공부하고 그리고 난 외국 키를 생성동일한 테이블의 기본 키에 대한 외래 키 참조 이유 이해?
emp_id is primary key
과 같은 테이블
에서 emp_id
-superior_emp_id which is a foreign key
참조 employee table
에서 발견되는 같은 테이블 이유에 기본 키에 대한 참조 이러한 데이터베이스 설계는 어느 누구도 나를 도울 수 있습니까?
우수한 직원도 직원입니다. 따라서 emp_id = 2에 대한 상급은 emp_id = 1 일 수 있습니다. 기본적으로 동일한 테이블의 행과 1 : 1 관계입니다. – Andomar
1 to n 실제로. 한 상급자는 여러 부하를 가질 수 있습니다. – Mchl