Re: Sort database names & maintain referential integrity

From: Jonathan Leffler <jleffler_at_earthlink.net>
Date: 2000/07/06
Message-ID: <3964853C.1AD71E99_at_earthlink.net>#1/1


domenm_at_my-deja.com wrote:

> I have very tricky problem here. I have a short list of tables and I
> want to sort their names in a way to maintain their referential
> integrity. For example:
> table1 is master of table3
> table3 is master of table4, table5 and table6
> table2 is also master of table3
> table5 is master of table7 ...
>
> So, is there any known algorithms to sort the tables in the right way?

It's called a topological sort.

On Unix, the tsort program implements a topological sort.

Knuth describes the algorithm in Vol 1 (section 2.2.3 in my 2nd Edn).

--
Jonathan Leffler (jleffler_at_informix.com, jleffler_at_earthlink.net)
Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN
#include <disclaimer.h>
Received on Thu Jul 06 2000 - 00:00:00 CEST

Original text of this message