Home > Database > Mysql Tutorial > How to Query Table Names from a Specific Database in SQL (MySQL, SQL Server, Oracle)?

How to Query Table Names from a Specific Database in SQL (MySQL, SQL Server, Oracle)?

Linda Hamilton
Release: 2025-01-09 07:29:46
Original
580 people have browsed it

How to Query Table Names from a Specific Database in SQL (MySQL, SQL Server, Oracle)?

Retrieving Table Names from a Specific Database Using SQL

This guide demonstrates how to efficiently retrieve table names from a designated database within a multi-database environment (MySQL, SQL Server, Oracle). The standard query:

<code class="language-sql">SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'</code>
Copy after login

returns all table names across all databases. To filter for a specific database, database-specific syntax is necessary.

SQL Server:

Utilize the TABLE_CATALOG parameter:

<code class="language-sql">SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG='dbName'</code>
Copy after login

Replace dbName with your database's name.

MySQL:

Employ the TABLE_SCHEMA parameter:

<code class="language-sql">SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='dbName' </code>
Copy after login

Substitute dbName with your database name.

Oracle:

Oracle uses a different approach, leveraging the DBA_TABLES view:

<code class="language-sql">SELECT TABLE_NAME FROM DBA_TABLES WHERE OWNER='dbName'</code>
Copy after login

Remember to replace dbName with your target database name. This query returns the table name and other relevant information. If you only need the table name, modify the SELECT statement accordingly.

The above is the detailed content of How to Query Table Names from a Specific Database in SQL (MySQL, SQL Server, Oracle)?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template