List names of all tables in a SQL Server 2012 schema

前端 未结 6 427
再見小時候
再見小時候 2021-02-02 06:05

I have a schema in SQL Server 2012.

Is there a command that I can run in SQL to get the names of all the tables in that schema that were populated by user?

I kno

相关标签:
6条回答
  • 2021-02-02 06:12
    SELECT t1.name AS [Schema], t2.name AS [Table]
    FROM sys.schemas t1
    INNER JOIN sys.tables t2
    ON t2.schema_id = t1.schema_id
    ORDER BY t1.name,t2.name
    
    0 讨论(0)
  • 2021-02-02 06:13

    SQL Server 2005, 2008, 2012 or 2014:

    SELECT * FROM information_schema.tables WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA = 'dbo'
    

    For more details: How do I get list of all tables in a database using TSQL?

    0 讨论(0)
  • 2021-02-02 06:19

    Your should really use the INFORMATION_SCHEMA views in your database:

    USE <your_database_name>
    GO
    SELECT * FROM INFORMATION_SCHEMA.TABLES
    

    You can then filter that by table schema and/or table type, e.g.

    SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
    
    0 讨论(0)
  • 2021-02-02 06:22
    select * from [schema_name].sys.tables
    

    This should work. Make sure you are on the server which consists of your "[schema_name]"

    0 讨论(0)
  • 2021-02-02 06:30
    SELECT t.name 
      FROM sys.tables AS t
      INNER JOIN sys.schemas AS s
      ON t.[schema_id] = s.[schema_id]
      WHERE s.name = N'schema_name';
    
    0 讨论(0)
  • 2021-02-02 06:32
    SELECT *
    FROM sys.tables t
    INNER JOIN sys.objects o on o.object_id = t.object_id
    WHERE o.is_ms_shipped = 0;
    
    0 讨论(0)
提交回复
热议问题