【问题标题】:How can I find a table in SQL Server 2016如何在 SQL Server 2016 中找到表
【发布时间】:2016-10-18 10:18:48
【问题描述】:

如何在 SQL Server 2016 中查找表?

我可以用它来查找当前数据库中的表:

SELECT *
FROM sys.Tables
WHERE name LIKE '%App_Current_Seq_Num%'

问题是,我在服务器上有几个数据库。

【问题讨论】:

  • 只是EXISTS dbo.Product

标签: sql database sql-server-2016


【解决方案1】:

请尝试以下 sql 查询。

select * from [YourDatabaseName].INFORMATION_SCHEMA.TABLES where TABLE_NAME LIKE '%App_Current_Seq_Num%'

【讨论】:

    【解决方案2】:

    sp_tablessys.tablesinformation_schema.tables 只会为您提供当前所选数据库中的表列表。使用以下未记录的存储过程为每个数据库运行此代码,每个结果集都显示属于它的表列表。

     sp_MSforeachdb 'SELECT "?" AS DB, * FROM [?].sys.tables WHERE name like ''%App_Current_Seq_Num%'''
    

    另一种选择是使用动态 SQL。

    【讨论】:

      【解决方案3】:

      你可以这样做

      use your_database_name
      
      SELECT *
      FROM sys.Tables
      WHERE name LIKE '%App_Current_Seq_Num%'
      

       SELECT *
       FROM your_database_name.sys.Tables
       WHERE name LIKE '%App_Current_Seq_Num%'
      

      或者,如果您想一次搜索多个数据库,请使用 union all 子句。 像这样的:

      SELECT * FROM database1.sys.Tables
      UNION ALL
      SELECT * FROM database2.sys.Tables
      

      【讨论】:

        【解决方案4】:

        我用过这个,效果很好:

        使用大师 去 执行 sp_MSforeachdb @command1='使用 ?;选择 * FROM 系统表 WHERE name LIKE ''%App_Current_Seq_Num%'''

        【讨论】:

          【解决方案5】:

          你可以使用SQL Search

          是一个简单的搜索控件,可以在sql server中使用

          查找表/视图/存储过程等...

          使用快速免费下载

          https://www.red-gate.com/products/sql-development/sql-search/index

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2018-03-07
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2023-03-10
            • 1970-01-01
            相关资源
            最近更新 更多