MySQL--delete/truncate/drop

  1. delete --- delete from SC where id = '1001' +++ delete the data, leaving the structure of the table (also known as defined in the table), the data and index table space will not be reduced
  2. truncate --- truncate demo3 SC +++ delete the data, leaving the table structure data and index table space recovery to the initial value of the size
  3. drop --- drop demo3 SC / drop database demo3 +++ delete all, space is released
  • truncate and delete data to delete only the structure of the table are not deleted, drop statement removes the structure of the table is dependent constraints (constrain), the trigger (Trigger), an index (index); dependent table stored in the procedure / function will be retained, but becomes invalid state.
  • delete statement is dml, the operation will be put in rollback segement, to take effect after the transaction commits; if there is a corresponding trigger, when the execution will be triggered. truncate, drop is ddl, operating with immediate effect, the original data is not put rollback segment can not be rolled back. Operation does not trigger the trigger.
  • delete statements do not affect the table occupied extent, the high water line to maintain the original position does not move. See truncate statement released to the default space minextents a extent, unless reuse storage; truncate will reset the high water line (back to the beginning).

Be careful using the drop and truncate, timely backups. Otherwise too late to cry.

  • Delete table with the drop.
  • Reserved tables will delete all data. If the transaction and has nothing to do with truncate. If and matters relating to, or want to trigger the trigger, or a delete.
  • If it is inside finishing table fragmentation, you can truncate keep reuse stroage, reintroduced into / insert the data.

 

 

Guess you like

Origin www.cnblogs.com/Dfrank/p/11839467.html