Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display all the names of databases containing particular table

Tags:

I have many databases in my SQL Server.

I have to just search for database names containg particular table name Heartbitmaster

I have many databases such as Gotgold, DVD, etc and I just want to find database names from query that contain this table Heartbitmaster.

I searched I tried for query:

SELECT      TABLE_NAME   FROM      INFORMATION_SCHEMA.TABLES  WHERE      TABLE_TYPE = 'base table'        AND table_schema = 'Heartbitmaster' 

but it didn't work.

I searched further and came across:

SELECT name, database_id, create_date FROM sys.databases  

but dont know how to arrange further where condition for search of table name

Please help me.

like image 545
C Sharper Avatar asked Aug 09 '13 06:08

C Sharper


People also ask

How do I get a list of table names in a database?

In MySQL, there are two ways to find the names of all tables, either by using the "show" keyword or by query INFORMATION_SCHEMA. In the case of SQL Server or MSSQL, You can either use sys. tables or INFORMATION_SCHEMA to get all table names for a database.

Which of the following queries is used to display all the databases present?

SQL language is a DML in DBMS. This is used to manipulate databases and the records kept in them. A database is a collection of structured information or data stored in any computer system.


1 Answers

I got it done through following query:

SELECT name FROM   sys.databases WHERE  CASE   WHEN state_desc = 'ONLINE'    THEN OBJECT_ID(QUOTENAME(name) + '.[dbo].[heartbit]', 'U')    END IS NOT NULL 
like image 175
C Sharper Avatar answered Oct 26 '22 17:10

C Sharper