How to List All Tables in a Schema in Oracle Database?


Introduction

In Oracle databases, a schema is a logical grouping of related objects, such as tables, views, and stored procedures. Each schema belongs to a specific database user and has a set of associated privileges. To list all tables in a schema in an Oracle database, you can use one of the views in the data dictionary. The `ALL_TABLES` view contains one row for each table in the current schema, while the `DBA_TABLES` view contains one row for each table in the entire database.

To list the tables in a schema, you can use a SELECT statement to query the `table_name` column from the appropriate view, and filter the results by schema using the `owner` column.

Definition

To list all tables in a schema in an Oracle database means to retrieve a list of all the tables that exist in a particular schema within the database. A schema is a collection of logical structures of data, or objects, in a database. It is a way to group related objects together.

To list the tables in a schema, you can use one of the views in the Oracle data dictionary. The `ALL_TABLES` view contains one row for each table in the current schema, and the `DBA_TABLES` view contains one row for each table in the entire database. To list the tables in a schema, you can use a query to select the `table_name` column from the appropriate view and filter the results by schema using the `owner` columngraph.

Listing All Tables in Schema

How to use the `ALL_TABLES` view to list all tables in the current schema −

Step -1

SELECT table_name FROM all_tables;

Step -2

This will return a list of all tables in the current schema. If you want to see the tables in another schema, you can specify the schema name as follows −

SELECT table_name FROM all_tables WHERE owner ='schema_name';

Step - 3

Replace 'schema_name' with the name of the schema you want to see the tables for.

You can also use the `DBA_TABLES` view to list all tables in the database, regardless of which schema they belong to. To do this, you can use the following query −

SELECT owner, table_name FROM dba_tables;

This will return a list of all tables in the database, along with the schema they belong to.

Example 1

Here is an example of how to list all tables in a schema in an Oracle database using the `ALL_TABLES` view −

SELECT table_name FROM all_tables WHERE owner = <'schema_name'>;

Replace <`schema_name`> with the name of the schema you want to see the tables for.

This query will return a list of all tables in the specified schema.

Here is an example of the output −

TABLE_NAME ---------- employees departments locations

You can also use the `DBA_TABLES` view to list all tables in the database, regardless of which schema they belong to. To do this, you can use the following query −

SELECT owner, table_name FROM dba_tables;

This will return a list of all tables in the database, along with the schema they belong to.

Example 2

Here is an example of how to list all tables in a schema in an Oracle database using the `ALL_TABLES` view −

SELECT table_name FROM all_tables WHERE owner = <'schema_name'>;

Replace <`schema_name`> with the name of the schema you want to see the tables for.

This query will return a list of all tables in the specified schema.

Here is an example of the output −

TABLE_NAME ---------- student_name roll_number departments year

You can also use the `DBA_TABLES` view to list all tables in the database, regardless of which schema they belong to. To do this, you can use the following query −

SELECT owner, table_name FROM dba_tables;

This will return a list of all tables in the database, along with the schema they belong to.

Conclusion

  • The `ALL_TABLES` view contains one row for each table in the current schema. You can use a SELECT statement to query the `table_name` column from this view, and filter the results by schema using the `owner` column.

  • The `DBA_TABLES` view contains one row for each table in the entire database. You can use a SELECT statement to query the `table_name` and `owner` columns from this view to list all tables in the database and their corresponding schema.

Updated on: 04-Oct-2023

36K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements