CREATE TABLE employee (
emp_id SMALLINT PRIMARY KEY,
first_name VARCHAR(10),
last_name VARCHAR(10),
birthdate DATE,
sex VARCHAR(1),
salary SMALLINT,
super_id SMALLINT,
branch_id SMALLINT
);
ALTER TABLE employee
ADD FOREIGN KEY (super_id) REFERENCES employee(emp_id);
ALTER TABLE employee
ADD FOREIGN KEY (branch_id) REFERENCES branch(branch_id);
ALTER TABLE employee
DROP FOREIGN KEY (super_id);
I am not able to drop the foreign key after adding it. Trying to learn SQL, thank you for the answers.
ERROR - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(super_id)' at line 2
Give your constraint a name:
ALTER TABLE employee
ADD CONSTRAINT fk_employee_superid__employee_employeeid
FOREIGN KEY (super_id) REFERENCES employee(emp_id);
Drop it by name:
ALTER TABLE employee
DROP CONSTRAINT fk_employee_superid__employee_employeeid;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.