Find databases containing a particular table in Azure SQL Database

Article for: SQL Server Teradata MySQL MariaDB

The query below finds all databases in Azure SQL Database instance containing a particular table (the table name must include its schema name). In this case the table is dbo.BuildVersion.

Query

select [name] as [database_name]
from sys.databases 
where 
    case when state_desc = 'ONLINE' 
        then object_id(quotename([name]) + '.[dbo].[BuildVersion]', 'U') 
    end is not null
order by 1

Columns

  • database_name - database names

Rows

  • One row: represents one database
  • Scope of rows: all databases containing the provided table schema and name
  • Ordered by: database name

Sample results

All databases containing the dbo.BuildVersion table.

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.