Issue
This Content is from Stack Overflow. Question asked by Tyler
Example: Is this recursive relationship written correctly? Would Mgr be marked as a primary key or is this code correct?
create table Employee (
EMPNO number(10) not null,
Mgr number(10),
constraint pk_Employee primary key (EMPNO),
constraint fk_emp_emp foreign key (Mgr) references Employee
);
Solution
Your code is correct. I checked it with the following sql server and It worked fine.
create table Employee (EMPNO int not null, Mgr int, constraint
pk_Employee primary key (EMPNO), constraint fk_emp_emp foreign key (Mgr) references Employee );
This Question was asked in StackOverflow by Student and Answered by S. R. Q. Behbahani It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.