Do you know about very dangerous command in Oracle DB to lose data? Simple action can erase all rows from table or indexed cluster without ability to restore!
The DDL command "Truncate Table" is executed faster than DML command "Delete" with the following commit. But if you work with important data then please don't hurry up and use the DML statement that can be rollbacked.
Be sure that the execution speed can be confirmed. SQLDetective has the option to confirm all DDL commands:
The most tools require to confirm data truncating because TRUNCATE is not a DML command, it's like "ALTER" re-creates partly your table or cluster. Be careful, if you have the "DROP ANY TABLE" system privilege then row truncating can be executed in tables or clusters of other schemas.
Do you remember that any DDL statement commits the DML commands executed earlier. For example, the result of following scripts are equal:
-- script 1
delete from table_first;
truncate table table_second;
--script 2
delete from table_first;
commit;
delete from table_second;
commit;
After truncating the indexed cluster you should rebuild the referenced indexes.
Developers and testers, be sure that there are enough confirmations and warnings about "TRUNCATE" command executions:
- in running tool;
- on manually typed script running;
- in pl/sql block with "EXECUTE IMMEDIATE" statement;
- after granting "DROP ANY TABLE" system privilege.
It'll be useful to have a code review rule that checks the available TRUNCATE command in scripts. In other case you or your users may lose data without ability to roll back.
The DDL command "Truncate Table" is executed faster than DML command "Delete" with the following commit. But if you work with important data then please don't hurry up and use the DML statement that can be rollbacked.
Be sure that the execution speed can be confirmed. SQLDetective has the option to confirm all DDL commands:
The most tools require to confirm data truncating because TRUNCATE is not a DML command, it's like "ALTER" re-creates partly your table or cluster. Be careful, if you have the "DROP ANY TABLE" system privilege then row truncating can be executed in tables or clusters of other schemas.
Do you remember that any DDL statement commits the DML commands executed earlier. For example, the result of following scripts are equal:
-- script 1
delete from table_first;
truncate table table_second;
--script 2
delete from table_first;
commit;
delete from table_second;
commit;
After truncating the indexed cluster you should rebuild the referenced indexes.
Developers and testers, be sure that there are enough confirmations and warnings about "TRUNCATE" command executions:
- in running tool;
- on manually typed script running;
- in pl/sql block with "EXECUTE IMMEDIATE" statement;
- after granting "DROP ANY TABLE" system privilege.
It'll be useful to have a code review rule that checks the available TRUNCATE command in scripts. In other case you or your users may lose data without ability to roll back.
No comments:
Post a Comment