Class02 DDL DMC TCL HWM
Class02 DDL DMC TCL HWM
question
suppose we insert data in the table and after that we fire a DDL command, so DDL will
first commit the data. This is the nature of DDL commands. then after if we do rollback,
it does not impACT ANYTHING, BECAUSE DATA IS COMMITTED.
Modify Table:
--> we can modify the type size of any column using the alter table modify command, we can
increase it easily but can not decrease it if any data exists because it will check the
existing data and if the size is greater than that then deny to decrease.
--> Increasing the length is easy, straight forward, but in case of size reduction, it
will check each and every record of the database. It will be a slow and time taking
process. Advisable in downtime only.
==================================================================================
Delete/Truncate/DROP
What is HWM
High water mark is the maximum amount of database blocks used so far by a segment. This mark cannot be reset by delete
operations. Does not matter , you delete and commit, HWM not reset.
The high water mark level is just a line separate the used blocks and free blocks.
The blocks above the HWM level is free blocks, they are ready to use.
The blocks below the HWM level is used blocks, they are already used.
For example, if you delete some huge records from the database, that data will delete but the blocks are not ready to used,
because that blocks are still below HWM level, so delete command never reset the HWM level,
At the same time you truncate the date, then the data will delete and that used blocks will goto above the HWM level, now
its ready to used. now they consider has free blocks.
3. Can we do rollback after drop --> NO. because drop is a ddl command. Rollback is not work for ddl only for dml
Answer:
1. we can not truncate here, because truncate will empty the whole table, which we do not
want
2. we can not fire the delete command, because deleting 5M rows from a table will
definitely hung the database. it will stuck and don't know when come back
3. Create table A_temp as select * from A where <condition> -- To fetch the required 5M
records
4. Now I have the required record which is needed for application in table A_temp
5. truncate main table. truncate table A ; -- this will be done in a few seconds and now
we have the application table empty and required data in temp table
6. Either we can rename the temp table to the main table and drop the main table (This is
an approach but not advisable because all the database objects like procedure, packages
and function who are using that table, will become uncompiled and we have to compile
again.)
OR
insert all records from temp table to main table
Note: Prefer to insert the data from temp table to main table, rather than drop the main
table and rename the temp to main. Why? because if we drop the main table then all
database objects (procedures, functions,packages etc) become invalid, we have extra work
to compile them all.
------------------------------------------------------------------------------------------
----