How do I get list of all tables in a database using TSQL?

前端 未结 17 1780
无人及你
无人及你 2020-11-22 14:37

What is the best way to get the names of all of the tables in a specific database on SQL Server?

17条回答
  •  囚心锁ツ
    2020-11-22 15:18

    The downside of INFORMATION_SCHEMA.TABLES is that it also includes system tables such as dtproperties and the MSpeer_... tables, with no way to tell them apart from your own tables.

    I would recommend using sys.objects (the new version of the deprecated sysobjects view), which does support excluding the system tables:

    select *
    from sys.objects
    where type = 'U'      -- User tables
    and is_ms_shipped = 0 -- Exclude system tables
    

提交回复
热议问题