Suppose I have some conceptual, not physical, E-R diagram describing a relational database. I want to sort all the tables in the database using a topological sort, where the partial ordering between tables is Table 1 has a foreign key onto Table 2.
When clearing out tables after putting test data in them, I would need to delete Table 1 above first, then Table 2, in order to not violate FK references. A topological sort on the FK relation gives me an ordering to clear the tables in.
It is possible to have a table with an FK to itself, providing a simple counter example where there is a cycle, and subsequently no topological sort. However, this self relationship could also be represented using a join table, which lists 2 rows of the table, where one refers to the other, and in this case there would be a topological sort.
By replacing direct FK references between tables with join tables, is it always possible to arrive at a structure that can be topologically sorted?