Skip to main content

Difference between Delete and Truncate in oracle sql plsql interview question and answer for fresher,intermediate and experienced.

 "Most important question asked in oracle sql plsql interview"

Introduction:

Delete and Truncate is used to remove the data from the relational table. SQL developer have to decide where to use these both concepts. By understanding the concept, it is useful for handling the data. Well analysis of all the rows to be deleted before using truncate command.

Difference:

Delete

Truncate

It is a Data Manipulation Language command.

It is a Data Definition Language command.

Syntax:

Delete from tablename where condition;

Delete from tablename;

Syntax:

Truncate table tablename;

Delete command is slower than truncate.

Truncate command is faster.

Delete contain the where clause.

Truncate don’t contain the where clause.

It is used to remove or delete the specified row or tuple from the table using where clause. In absence of where clause, it is used to delete all the rows or tuples from the table.

It is used to delete all the rows or tuples from the table.

Deleted Data can be backed using the rolled command.

Deleted Data cannot be backed using the rolled command.

Trigger is fired.

Trigger is not fired.

It doesn’t remove the records permanently.

It removes the records permanently.

In order to use delete command, we need to delete permission over the table.

In order to use truncate command, we need to

Alter permission over the table.

Integrity constraint will be same.

Integrity constraint will not be removed.

It maintains the transaction log of the removed rows.

It don’t maintain the transaction log of the removed rows.

It uses the row lock.

It uses the table lock.

It uses the undo space more than truncate.

It does not use the undo space like delete.

Autoincrement counter is not reset.

Autoincrement counter is reset.

It can be used with indexed views.

It cannot be used with an indexed view.

It uses the more transaction space.

It uses the less transaction space.

It does not recover space.

It recovers space.

Delete never lowers the high-water mark.

Truncate lowers the high-water mark.

Flashwork  work across .

It prevents flashwork.

It is less used for deleting the large tables.

It is used for deleting the large tables.

If foreign key is enabled, data can be deleted.

If foreign key is enabled, data cannot be deleted. We have to disable the foreign key for the data to be deleted.

It does not reset the high-water mark.

It reset the high-water mark.

It is not auto-commit statement.

It is an auto-commit statement.

It does not remove the table size space.

It removes the table size space.

It keeps tracking for the deleted rows.

It doesn’t keep tracking for the deleted rows.

Manual commit

Automatic commit

It deletes the data without resetting the table identity.

It reset the particular table identity.

From oracle 12c,on delete cascade which deletes the parent and child table.

From oracle 12c, truncate table table_name cascade which deletes the parent and child table.

Data is copied to undo tablespace before delete operation.

Data is not copied to undo tablespace before truncate operation.

Foreign key is present.

Foreign key is not present.

Transaction performance is not better than truncate.

It’s transaction performance is better than delete.

HVM is not updated and it hold the undo tablespace.

HVM is updated and it don’t hold the undo tablespace.

Table’s row which is deleted which are the logged operation and number of rows which are deleted present in the transaction log makes it slower.

Table’s row which is deleted which are not the logged operation and number of rows which are deleted not present in the transaction log. Deallocation of data pages of the table which really helps in faster.

 

Comments

Popular posts from this blog

Difference between union and union all in oracle sql plsql

"This is one of the most important questions that interviewer might be asking in an interview.Infyosis,Linked group,Kyndryl,Vodafone Idea,IBM and Mphasis etc" INTRODUCTION: It is said to be set operators which is used to combine, add or concatenate two or more result sets. It is used in the multiple select statements where to combine to produce the final desired results.In other words,multiple select statements of similar column name in same order and having same data type to produce the unified result.In MIS datalake,when you are adding the modules of GST reconciliation which is to be used in micros in Excel or VB script, union and union all set operator is preferred for eliminating duplicate records or keeping duplicate records as per business requirement. Column must be of the same datatype for these operations of one select statement with another select statements. Columns must be in the same order in this set operators in the multiple select statements. Same number of co

Difference between decode and case oracle sql plsql interview question and answer

" This is the most accepted question for PLSQL developer role.It has been asked in many interviews like Mphasis and Kyndryl. "  INTRODUCTION: Case was came after oracle database version 8.1.6 whereas decode was came before oracle database version 8.1.6 .Decode and case statements in an oracle work or acts like if then elsif conditional statements. if sal='2000000' then 'General Manager' elsif sal='3000000' then 'Senior Manager' elsif sal='1200000' then 'Manager' else 'Employee' end if; create table student_details(Student_RollNo Number,Student_Name Varchar2(20),student_marks Number,student_result varchar2(1)); insert into student_details values (100,'Rahul',90,'P'); insert into student_details values (101,'Rakesh',30,'F'); insert into student_details values (102,'Ram',60,'P'); insert into student_details values (103,'Rohan',10,'F'); insert into student_detai

Difference view and Materialized view in Oracle SQL PLSQL Interview Question and Answer.

 " This is excepted question in oracle interview. It is asked in oracle technical support,PLSQL developer, SQL Analyst and SQL developer. " INTRODUCTION: View and Materialized view are called as the database object or the named query. View is the virtual table which stores the select statement from the base table by execution of the sql query at the runtime. View Query is running for the view definition. In the case of the materialized view, the data from the base table is loaded in the temporary or physical memory location by which the materialized view gets refreshed and all the dependent tables on the materialized view are also get updated after refresh operation. Materialized views are used in lakhs lines of code. In the data lake, tables are dependent on the master table to get updated where more than lakhs line of codes, today every reporting is based on this, in that case materialized view are used and preferred on the master tables. An activity of materialized view wi