How to Delete Table, Index or Schema Statistics in Oracle Database

To delete table, index, or schema statistics in Oracle Database, you can use the following methods:

Deleting Table Statistics:
If you want to delete statistics for a specific table, you can use the DBMS_STATS.DELETE_TABLE_STATS procedure.

Here’s an example:

BEGIN
DBMS_STATS.DELETE_TABLE_STATS(ownname => ‘SCHEMA_NAME’, tabname => ‘TABLE_NAME’);
END;
/
Replace ‘SCHEMA_NAME’ with the name of the schema that owns the table and ‘TABLE_NAME’ with the name of the table for which you want to delete the statistics.

Deleting Index Statistics:
To delete statistics for an index, you can use the DBMS_STATS.DELETE_INDEX_STATS procedure.

Here’s an example:

BEGIN
DBMS_STATS.DELETE_INDEX_STATS(ownname => ‘SCHEMA_NAME’, indname => ‘INDEX_NAME’);
END;
/
Replace ‘SCHEMA_NAME’ with the name of the schema that owns the index and ‘INDEX_NAME’ with the name of the index for which you want to delete the statistics.

Deleting Schema Statistics:
If you want to delete statistics for an entire schema, you can use the DBMS_STATS.DELETE_SCHEMA_STATS procedure.

Here’s an example:

BEGIN
DBMS_STATS.DELETE_SCHEMA_STATS(ownname => ‘SCHEMA_NAME’);
END;
/
Replace ‘SCHEMA_NAME’ with the name of the schema for which you want to delete the statistics.

Remember, deleting statistics will cause the optimizer to recalculate them the next time a relevant query is executed. Be cautious when deleting statistics, as it may affect the performance of subsequent queries until new statistics are gathered.



Yorum bırakın