Show Database


SHOW DATABASES : 

Sometimes  you face a situation where you need to list down all the available databases. MySQL provides a convenient way to list down all the databases using SHOW DATABASES command where as there is no particular command in MS SQL Server to show or list the databases but, you can use the SELECT...FROM command as a work around list down available databases.

List Databases using SQL

The SQL SHOW DATABASES statement is used to list down all the available databases in MySQL database. You can use SHOW SCHEMAS as an alternate command for SHOW DATABASES.

Syntax

Following is the syntax of SQL SHOW DATABASES to list down all the available databases in MySQL -

SHOW DATABASES [LIKE 'pattern' | WHERE expr] ;

We can use LIKE or WHERE clause along with SHOW DATABASES to filter out a list of databases.

Example

Following is an example to list down all the available databases.

SHOW DATABASES;

The output will be displayed as follows. This output depends on the number of databases available in the system -

Database
performance_schema
information_schema
mysql
sample_DB

Following is an example to list down all the databases whose name starts with sample.

SHOW DATABASES LIKE 'sample%';

The output will be displayed as follows -

Database (sample%)
sample_DB

The SHOW SCHEMAS Statement

You can use the SHOW SCHEMAS statement as an alternate for the SHOW DATABASES statement.

Syntax

Following is the syntax of the SQL SHOW SCHEMAS statement to list down all the available databases in MySQL -

SHOW SCHEMAS [LIKE 'pattern' | WHERE expr] ;

We can use LIKE or WHERE clause along with SHOW SCHEMAS to filter out a list of databases.

Example

Following is an example to list down all the available databases.

SHOW SCHEMAS;

The output will be displayed as follows. This output depends on the number of databases available in the system -

Database
performance_schema
information_schema
mysql
sample_DB

Following is an example to list down all the databases whose name starts with sample.

SHOW SCHEMAS LIKE 'sample%';

The output will be displayed as follows -

Database (sample%)
sample_DB

The SELECT...FROM Statement

If you are working with MS SQL Server then you can use the SELECT...FROM statement to list down all the available databases as shown below.

SQL> SELECT * FROM sys.databases;

Output

If we execute the above query, it returns a table that lists down all the databases and associated information about the databases.

namedatabase_idsource_database_idowner_sid
master1NULL001
tempdb2NULL001
model3NULL001
msdb4NULL001
sample_DB5NULL001000

The EXEC sp_databases Statement

If you are using MS SQL Server then you can use the following EXEC sp_databases statement to list down all the databases -

SQL> EXEC sp_databases;

Output

This will display the same result as we got from SELECT...FROM statement.

namedatabase_idsource_database_idowner_sid
master1NULL001
tempdb2NULL001
model3NULL001
msdb4NULL001
sample_DB5NULL001000

SHOW DATABASES : 

Sometimes  you face a situation where you need to list down all the available databases. MySQL provides a convenient way to list down all the databases using SHOW DATABASES command where as there is no particular command in MS SQL Server to show or list the databases but, you can use the SELECT...FROM command as a work around list down available databases.

List Databases using SQL

The SQL SHOW DATABASES statement is used to list down all the available databases in MySQL database. You can use SHOW SCHEMAS as an alternate command for SHOW DATABASES.

Syntax

Following is the syntax of SQL SHOW DATABASES to list down all the available databases in MySQL -

SHOW DATABASES [LIKE 'pattern' | WHERE expr] ;

We can use LIKE or WHERE clause along with SHOW DATABASES to filter out a list of databases.

Example

Following is an example to list down all the available databases.

SHOW DATABASES;

The output will be displayed as follows. This output depends on the number of databases available in the system -

Database
performance_schema
information_schema
mysql
sample_DB

Following is an example to list down all the databases whose name starts with sample.

SHOW DATABASES LIKE 'sample%';

The output will be displayed as follows -

Database (sample%)
sample_DB

The SHOW SCHEMAS Statement

You can use the SHOW SCHEMAS statement as an alternate for the SHOW DATABASES statement.

Syntax

Following is the syntax of the SQL SHOW SCHEMAS statement to list down all the available databases in MySQL -

SHOW SCHEMAS [LIKE 'pattern' | WHERE expr] ;

We can use LIKE or WHERE clause along with SHOW SCHEMAS to filter out a list of databases.

Example

Following is an example to list down all the available databases.

SHOW SCHEMAS;

The output will be displayed as follows. This output depends on the number of databases available in the system -

Database
performance_schema
information_schema
mysql
sample_DB

Following is an example to list down all the databases whose name starts with sample.

SHOW SCHEMAS LIKE 'sample%';

The output will be displayed as follows -

Database (sample%)
sample_DB

The SELECT...FROM Statement

If you are working with MS SQL Server then you can use the SELECT...FROM statement to list down all the available databases as shown below.

SQL> SELECT * FROM sys.databases;

Output

If we execute the above query, it returns a table that lists down all the databases and associated information about the databases.

namedatabase_idsource_database_idowner_sid
master1NULL001
tempdb2NULL001
model3NULL001
msdb4NULL001
sample_DB5NULL001000

The EXEC sp_databases Statement

If you are using MS SQL Server then you can use the following EXEC sp_databases statement to list down all the databases -

SQL> EXEC sp_databases;

Output

This will display the same result as we got from SELECT...FROM statement.

namedatabase_idsource_database_idowner_sid
master1NULL001
tempdb2NULL001
model3NULL001
msdb4NULL001
sample_DB5NULL001000

Talk to us?

Post your blog