Does anyone know about a good algorithm for sorting the tables in the order they must be populated, given their constraints?

Thank you very much in advance.