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

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

    Thanks to Ray Vega, whose response gives all user tables in a database...

    exec sp_msforeachtable 'print ''?'''

    sp_helptext shows the underlying query, which summarises to...

    select * from dbo.sysobjects o 
    join sys.all_objects syso on o.id =  syso.object_id  
    where OBJECTPROPERTY(o.id, 'IsUserTable') = 1 
    and o.category & 2 = 0 
    
    0 讨论(0)
  • 2020-11-22 15:24
    SELECT * FROM INFORMATION_SCHEMA.TABLES 
    

    OR

    SELECT * FROM Sys.Tables
    
    0 讨论(0)
  • 2020-11-22 15:24
    USE YourDBName
    GO 
    SELECT *
    FROM sys.Tables
    GO
    

    OR

    USE YourDBName
    GO
    SELECT * FROM INFORMATION_SCHEMA.TABLES 
    GO
    
    0 讨论(0)
  • 2020-11-22 15:26
    --for oracle
    select tablespace_name, table_name from all_tables;
    

    This link can provide much more information on this topic

    0 讨论(0)
  • 2020-11-22 15:28
    exec sp_msforeachtable 'print ''?'''
    
    0 讨论(0)
提交回复
热议问题