We have a directed graph represented by an edge table. How can we detect the cycle in pure SQL ?
CREATE TABLE edges(id integer primary key identity, from_node int, to_node int);
CREATE NONCLUSTERED INDEX index_edges_of2 ON edges(from_node);
INSERT INTO edges(from_node,to_node) VALUES(1,2),(2,3),(3,1);