- SQL Basics
- SQL Introduction
- SQL Syntax
- SQL Sample Database
- SQL SELECT
- SQL WHERE
- SQL ORDER BY
- SQL DISTINCT
- SQL LIMIT
- SQL FETCH
- SQL AND
- SQL OR
- SQL BETWEEN
- SQL IN
- SQL LIKE
- SQL IS NULL
- SQL Comparison Operators
- SQL Logical Operators
- SQL Alias
- SQL CASE
- Joins and Subqueries
- SQL INNER JOIN
- SQL LEFT JOIN
- SQL RIGHT JOIN
- SQL FULL OUTER JOIN
- SQL SELF JOIN
- SQL CROSS JOIN
- SQL Subquery
- SQL Correlated Subquery
- SQL UNION
- SQL INTERSECT
- SQL EXCEPT
- Aggregate Functions
- SQL AVG
- SQL COUNT
- SQL MAX
- SQL MIN
- SQL SUM
- SQL GROUP BY
- SQL HAVING
- SQL ROLLUP
- SQL CUBE
- SQL GROUPING SETS
- Database Management
- SQL CREATE DATABASE
- SQL ALTER DATABASE
- SQL DROP DATABASE
- SQL BACKUP DATABASE
- SQL SHOW DATABASES
- SQL SELECT DATABASE
- Table Management
- SQL CREATE TABLE
- SQL ALTER TABLE
- SQL ADD COLUMN
- SQL DROP COLUMN
- SQL DROP TABLE
- SQL TRUNCATE TABLE
- SQL SHOW TABLES
- SQL RENAME TABLE
- SQL Constraints
- SQL Primary Key
- SQL Foreign Key
- SQL UNIQUE Constraint
- SQL CHECK Constraint
- SQL NOT NULL Constraint
SQL SHOW DATABASES
The SHOW DATABASES statement is a fundamental command used to list all the databases currently available on a database server. Think of it as opening a "File Explorer" for your SQL server it allows you to see exactly which projects and data silos you have permission to access before you start writing queries.
Key Features of SQL SHOW DATABASES
- System Overview: It provides an immediate snapshot of all logical database containers on the server.
- Security-Aware: The list you see is filtered based on your user privileges. If your account doesn't have permissions for a specific database, it won't appear in the list.
- Platform Specific: While it is the standard command for MySQL and MariaDB, other systems like PostgreSQL or SQL Server use different methods to achieve the same result.
SQL SHOW DATABASES Syntax
The syntax is incredibly straightforward. You don't need to specify any tables or columns because you are querying the server's metadata itself.
SHOW DATABASES;
Output Example:
When you run this, you will notice system databases like information_schema and mysql. These are internal databases used by the engine to store metadata and configurations. Your actual project data will typically be in a custom-named database like test_db.
SELECT * FROM DATABASES;. In MySQL, this will result in an error. Always use the SHOW keyword for this specific task.
Using LIKE to Filter Databases
In environments with dozens or hundreds of databases, scrolling through a long list is inefficient. You can use the LIKE clause with wildcards to find exactly what you're looking for.
The percent sign (%) acts as a wildcard representing zero or more characters.
-- Find databases that start with "test"
SHOW DATABASES LIKE 'test%';
Output:
| Database Name |
|---|
| test_db |
| test_analytics |
prod_users, dev_users, test_users). This makes filtering with LIKE much more powerful when managing multiple environments.
Checking Databases in SQL Server
It is important to remember that SQL syntax can vary between different Database Management Systems (DBMS). If you are working in Microsoft SQL Server, the SHOW DATABASES command will not work. Instead, you query the system catalog:
-- SQL Server variant
SELECT name FROM sys.databases;
Similarly, in PostgreSQL, you would use the command line shortcut \l or query the pg_database table.
Summary
- MySQL/MariaDB: Use
SHOW DATABASES;to see all available schemas. - Filtering: Use
LIKE 'pattern%'to narrow down the results when dealing with many databases. - Cross-Platform: Always check your specific DBMS documentation, as SQL Server and PostgreSQL use different system queries (like
sys.databases). - Context: After seeing the list, your next step is usually the
USE database_name;command to start working within one.