I am making a database and I need to convert the column SuperDni into a foreign key in reference of the column Dni. I want to delete in cascade, but if I put CASCADE in place of NO ACTION, I get an error:
cycles or multiple cascade paths
Only if I do this I can create the table, but I need to delete the registers in cascade if I delete a key in reference of that key.
For example if I delete the Dni = 1 I need to delete the registers that contain that Dni value in the column SuperDni.
Is there a way to do this? because I am learning to use MySQL and SQL Server and I could do it in MySQL.
CREATE TABLE Empleado ( Nombre VARCHAR(20) NOT NULL, Apellido1 VARCHAR(20) NOT NULL, Apellido2 VARCHAR(20), Dni VARCHAR(20) PRIMARY KEY NOT NULL, Sexo VARCHAR(1), Sueldo INT, SuperDni VARCHAR(20), Dno INT, FOREIGN KEY(SuperDni) REFERENCES Empleado(Dni) ON DELETE NO ACTION ON UPDATE NO ACTION ); INSERT INTO Empleado VALUES("a", "a", "a", "1", "a", 200, NULL, NULL); INSERT INTO Empleado VALUES("b", "b", "b", "2", "b", 140, "1", NULL); INSERT INTO Empleado VALUES("c", "c", "c", "3", "c", 230, "1", NULL); INSERT INTO Empleado VALUES("d", "d", "d", "4", "d", 110, NULL, NULL); I need to do it of this form because I am studying the university.