I have table like this:
CREATE TABLE MyTable (
Id INT NOT NULL PRIMARY KEY,
ParentId INT NOT NULL
);
ALTER TABLE MyTable ADD FOREIGN KEY (ParentId) REFERENCES MyTable(Id);
select * from MyTable
desc MyTable
INSERT INTO MyTable (Id, ParentId) VALUES (0, 0);
INSERT INTO MyTable (Id, ParentId) VALUES (1, 0);
INSERT INTO MyTable (Id, ParentId) VALUES (2, 4);
INSERT INTO MyTable (Id, ParentId) VALUES (3, 2);
INSERT INTO MyTable (Id, ParentId) VALUES (4, 3);
How to find a circular reference in table references?