Sql-server – How to get dependencies order

constraintforeign keysql-server-2008-r2t-sql

I have a Database Called Total and I have about 40 tables in it.I am trying to move the tables in the database into a different server So I have prepared all the create table scripts but the problem is all the tables have foreign keys so I want to know the order in which I have to execute the tables.

Is there any way to know it?

Best Answer

Solution 1:

Script all of your foreign keys out and create the tables on the new server without foreign keys. Load the data, then rerun the scripts to create the foreign keys.

Solution 2:

Backup the database, the restore it to the new server.

Solution 3:

Run a query similar to this and figure out the dependencies for yourself.

Pick the one that sounds like the least work :)