Database Objects
Practical Oracle SQL for reviewing users, tables, indexes, invalid objects and database object status.
Understand what exists in the database
These queries provide a practical starting point for investigating schemas, database objects and object status across an Oracle environment.
Review database users
Review database users and their current account status. This is useful when establishing which schemas exist and whether accounts are currently available.
SELECT
username,
account_status,
created,
default_tablespace,
temporary_tablespace
FROM dba_users
ORDER BY username;Find tables by schema
Use this query to review tables owned by a particular schema. Replace the schema name with the owner you want to investigate.
SELECT
owner,
table_name,
tablespace_name,
num_rows,
last_analyzed
FROM dba_tables
WHERE owner = UPPER('&OWNER')
ORDER BY table_name;Review indexes for a schema
Review index names, associated tables, status and index type for objects belonging to a particular schema.
SELECT
owner,
index_name,
table_name,
index_type,
status,
visibility
FROM dba_indexes
WHERE owner = UPPER('&OWNER')
ORDER BY table_name, index_name;Find invalid database objects
Invalid objects can be an important operational clue after deployments, upgrades, migrations or other database changes.
SELECT
owner,
object_type,
object_name,
status
FROM dba_objects
WHERE status <> 'VALID'
ORDER BY owner, object_type, object_name;Summarize objects by schema and type
A quick inventory of object counts can help establish the size and composition of a schema before deeper investigation.
SELECT
owner,
object_type,
COUNT(*) AS object_count
FROM dba_objects
GROUP BY owner, object_type
ORDER BY owner, object_type;Review objects for one schema
Use this query when you need a focused view of all objects and their status within a particular schema.
SELECT
owner,
object_type,
object_name,
status,
last_ddl_time
FROM dba_objects
WHERE owner = UPPER('&OWNER')
ORDER BY object_type, object_name;Object status is a starting point, not the diagnosis.
An invalid object should normally be investigated in the context of the object type, recent DDL or deployment activity, dependencies and any associated compilation errors.
