SQL Listing Databases.

Using SQL statement to list all databases

To list all the databases you must have privileges to use statements for that.

Listing databases in MySQL

In MySQL you can use the SHOW statement.

Syntax:
SHOW {DATABASES | SCHEMAS}  [LIKE 'pattern' | WHERE expr]
Show databases example:
SHOW DATABASES LIKE 'f%'

This will list all the databases which have a name that start with a 'f' character.
You can accomplish the same thing with using a where statement.

Here is an example:
SHOW DATABASES WHERE `database` LIKE 'f%'

Observe the special single quotes around the database column.

Listing databases in SQL server

In SQL server you can select name from master.dbo.sysdatabases.

Show databases example:
SELECT name FROM master.dbo.sysdatabases
WHERE name LIKE 'C%'

This will list all the databases which have a name that start with a 'C' character.

Listing databases in PostgreSQL

In SQL server you can select datname from pg_database.

Show databases example:
SELECT datname FROM pg_database
WHERE datname LIKE 'C%'

This will list all the databases which have a datname that start with a 'C' character.

Listing databases in Oracle

A database in Oracle is something completely different than e.g. in SQL Server, PostgrSQL or MySQL.
Each database is (more or less) a different Oracle installation.
To show the database name you must login with the DBA privilege as user SYSTEM for instance.

You can then show the the database name with:
SELECT NAME FROM v$database
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.