Differentiate between the DELETE and TRUNCATE commands

Rows can be deleted from a table using the DELETE command, and conditional parameters can be specified using the WHERE clause. After a delete statement, you can make a commit or rollback.

Example

Employee_Table

emp_id emp_name salary dept_id manager_id
E1 Rahul 15000 D1 M1
E2 Manoj 15000 D1 M1
E3 James 55000 D2 M2
E4 Michael 25000 D2 M2
E5 Ali 20000 D10 M3
E6 Robin 35000 D10 M3

The following query will delete all the employees with salaries greater than 20000.

DELETE FROM Employee_Table
WHERE salary > 20000;

Output

Employee_Table

emp_id emp_name alary dept_id manager_id
E1 Rahul 15000 D1 M1
E2 Manoj 15000 D1 M1
E5 Ali 20000 D10 M3

TRUNCATE purges the table of all rows. This option cannot be undone.

Example

Employee_Table

emp_id emp_name salary dept_id manager_id
E1 Rahul 15000 D1 M1
E2 Manoj 15000 D1 M1
E3 James 55000 D2 M2
E4 Michael 25000 D2 M2
E5 Ali 20000 D10 M3
E6 Robin 35000 D10 M3
TRUNCATE TABLE Employee_Table;

Output

Employee_Table

emp_id emp_name salary dept_id manager_id