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

前端 未结 17 1953
无人及你
无人及你 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:19

    Well you can use sys.objects to get all database objects.

     GO
     select * from sys.objects where type_desc='USER_TABLE' order by name
     GO
    

    OR

    --  For all tables
    select * from INFORMATION_SCHEMA.TABLES 
    GO 
    
      --- For user defined tables
    select * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='BASE TABLE'
    GO
    
      --- For Views
    select * from INFORMATION_SCHEMA.TABLES where TABLE_TYPE='VIEW'
    GO
    

提交回复
热议问题