i'm getting an error? i want to create a foreign key in the employee table --(Dept_id) foreign key

Viewed 26
create table employee
(
    Emp_id int not null,
    Emp_firstname varchar(20),
    Emp_lastname varchar(20),
    Emp_Address varchar(20),
    Phone_no int,

    primary key(Emp_id)
);

create table Department
(
    Dept_id int not null,
    Dept_name varchar(20),

    primary key(Dept_id)
);

alter table employee
    add foreign key(Dept_id) references Department(Dept_id)

I get this error:

Msg 1769, Level 16, State 1, Line 16
Foreign key 'Dept_id' references invalid column 'Dept_id' in referencing table 'employee'.

Msg 1750, Level 16, State 0, Line 16
Could not create constraint or index. See previous errors.

0 Answers
Related