Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

malay_neerav's avatar

Please help with the code by finding the error

CREATE TABLE employee ( emp_id INT PRIMARY KEY, first_name VARCHAR(40), last_name VARCHAR(40), birth_date DATE, sex VARCHAR(1), salary INT, super_id VARCHAR(40), branch_id INT );

CREATE TABLE branch ( branch_id INT PRIMARY KEY, branch_name VARCHAR(40), mgr_id INT, mgr_start_date DATE, FOREIGN KEY(mgr_id) REFERENCES employee(emp_id) ON DELETE SET NULL );

ALTER TABLE employee ADD FOREIGN KEY(branch_id) REFERENCES branch(branch_id) ON DELETE SET NULL;

ALTER TABLE employee ADD FOREIGN KEY(super_id) REFERENCES employee(emp_id) ON DELETE SET NULL;

Its showing Error: Referencing column 'super_id' and referenced column 'emp_id' in foreign key constraint 'employee_ibfk_2' are incompatible.

0 likes
2 replies
tykus's avatar

The FK and referenced column must be the same type and size - currently, super_id is a VARCHAR type, and you try to reference emp_id which is a INT type.

1 like

Please or to participate in this conversation.