How to know dependency on a table
You should do it in two passes:

First create the tables:

create table Table1 (..., constraint pk_table1 primary key (...));
create table Table2 (..., constraint pk_table2 primary key (...));
..
create table TableN (..., constraint pk_tableN primary key (...));


Then add the foreign key constraints:

alter table Table1 add constraint fk_table1_tablex 
    foreign key (...) 
    references TableX (...);
alter table Table2 add constraint fk_table2_tabley 
    foreign key (...) 
    references TableY (...);
...


This way the there is no order dependency.