-- USE test;
DROP TABLE Delete_test;

CREATE TABLE Delete_Test (
    PRIMARY KEY (A),
	A DECIMAL(3,0),
	B DECIMAL(3,0),
		FOREIGN KEY (B) 
			REFERENCES Delete_Test(A) 
			ON DELETE CASCADE
);

INSERT INTO Delete_Test (A,B) 
VALUES 	(2,NULL),
		(3,NULL),
		(4,NULL),
		(5,NULL),
		(7,NULL),
		(9,NULL),
		(6,NULL);

UPDATE Delete_Test 
   SET B = 4 
 WHERE A = 2;
UPDATE Delete_Test 
   SET B = 4 --
 WHERE A = 3;
UPDATE Delete_Test 
   SET B = 3 
 WHERE A = 4;
UPDATE Delete_Test 
   SET B = 2 
 WHERE A = 5;
UPDATE Delete_Test 
   SET B = 2 
 WHERE A = 7;
UPDATE Delete_Test 
   SET B = 5 
 WHERE A = 9;
UPDATE Delete_Test 
   SET B = 4 
 WHERE A = 6;

SELECT * 
  FROM Delete_Test 
 ORDER BY A;

-- If we delete row where A = 3 or 4 then all the cascades delete every row
DELETE FROM Delete_Test 
 WHERE A = 2;
 
SELECT * 
  FROM Delete_Test 
 ORDER BY A;
