How to list all table names in sql server 2005 as per dependability order

Answered How to list all table names in sql server 2005 as per dependability order

  • Tuesday, May 22, 2012 12:19 PM
     
     

    Hello all ,

    I need to know how to list all table names in sql server 2005 as per dependability order.

    for example below are three table in sql server 2005 database

    County(id ,  name)

    City(id, countryid, name)

    Contact(id , cityid , name)

    Account(id , contactid , name)

    Contract(id accountid , name)

    And we have fill above records in the same order because of foreign key constraint.

    Like the same above . I have 150 tables in database and foreign key constraint between some tables.

    Is there any script through which I can list out the table name in exact way like which need to fill first , second and so on...


    --RDBurmon

All Replies

  • Tuesday, May 22, 2012 6:52 PM
     
     
    I don't.  However, before doing data imports, I have a script that drops all FK constraints.  Then I do my updates in whatever order I want.  Then I have a script that rebuilds my FK constraints. 
  • Tuesday, May 22, 2012 8:13 PM
     
     
    This forum is for Master Data Services, you may want to post this question to SQL Server Forum, more people will see your question there. :)

    Yang Wang (Microsoft SQL Server Master Data Services)

  • Saturday, June 02, 2012 8:11 AM
    Moderator
     
     Answered

    Hello RDBurmon,

    Please refer to the following T-SQL statement to get all tables in a database:
    USE DB_Name
    GO
    SELECT * FROM sys.Tables
    Order by name ASC
    GO

    If you have any more questions about T-SQL, I think that you can post the questions in SQL Server T-SQL forum.
    http://social.msdn.microsoft.com/Forums/en-US/transactsql/threads

    Regards,
    Bin Long


    Bin Long

    TechNet Community Support

  • Saturday, January 05, 2013 6:11 AM
     
     

    here where i can put my database name..if i dont know the database name ...how to find it.

    i need query to find the database ,table name??