OK, this is an ugly kludge for SQL Server 2000.
Replace the snippet for creating the preorder table with the one below.
I can't think of a better way to do this.
-- Create a preorder table using the database
-- relationships between tables. By definition,
-- a table A will be 'less than' a table B if
-- B has a foreign key pointing to A.
-- SQL Server 2000 version.
SELECT A, B
-- May be multiple relationships between two
-- tables but we only need one
-- Get name of parent table pointing to foreign table
so2.name as B,
-- Get name of foreign table by deleting
-- name of parent table (along with punctuation)
-- from name of foreign key constraint
RIGHT(so1.name,LEN(so1.name) - (LEN(so2.name)+4)) as A
so1.parent_obj = so2.id
-- Restrict sysobjects to foreign key constraints
-- Make sure name of foreign table represents
-- a real table because sysobjects will append
-- 1, 2, etc. to foreign key constraint name if
-- multiple relationships exist between a pair of them
RIGHT(so1.name,LEN(so1.name) - (LEN(so2.name)+4)) IN (SELECT NAME FROM sysobjects WHERE xtype = 'U')
ORDER BY A, B