Summary -
In this topic, we described about the DELETE All Rows with detailed example.
Sometimes, there are requirements to delete the entire table data to free up the memory or deleting data from temporary tables etc,.
DELETE statement used to delete the data from the table and frees up the memory that is utilized by table till the deletion. We should all make a note that the deleted data, won't be recovered until or unless it is specified as recoverable.
Executing DELETE statement without WHERE clause deletes entire table data. So be cautious while using DELETE statement, it can end up by deleting the whole table data if you are used WHERE clause.
Syntax -
DELETE FROM table_name;
- table_name – Specifies the name of the table.
Example –
Let us consider below table(s) as an example table(s) to frame the SQL query for getting the desired results.
employee_details -
emp_id | emp_name | designation | manager_id | date_of_hire | salary | dept_id |
---|---|---|---|---|---|---|
001 | Employee1 | Director | 2019-07-11 | 45000.00 | 1000 | |
002 | Employee2 | Director | 2019-07-11 | 40000.00 | 2000 | |
003 | Employee3 | Manager | Employee1 | 2019-07-11 | 27000.00 | 1000 |
004 | Employee4 | Manager | Employee2 | 2019-10-08 | 25000.00 | 2000 |
005 | Employee5 | Analyst | Employee3 | 2019-07-11 | 20000.00 | 1000 |
006 | Employee6 | Analyst | Employee3 | 2019-10-08 | 18000.00 | 1000 |
007 | Employee7 | Clerk | Employee3 | 2019-07-11 | 15000.00 | 1000 |
008 | Employee8 | Salesman | Employee4 | 2019-09-09 | 14000.00 | 2000 |
009 | Employee9 | Salesman | Employee4 | 2019-10-08 | 13000.00 | 2000 |
Scenario – Deleting all rows from existing table.
Requirement – Delete all rows from employee_details table. The query was as follows –
DELETE FROM employee_details;
By executing above query, we can delete all rows from employee_details. The output was as follows -
emp_id | emp_name | designation | manager_id | date_of_hire | salary | dept_id |
---|---|---|---|---|---|---|
Scenario – Verifying table.
Requirement – Verifying employee_details table to check all the rows deleted or not. The query was as follows –
SELECT * FROM employee_details;
By executing above query,we can verify the employee_details table. The output was as follows -
emp_id | emp_name | designation | manager_id | date_of_hire | salary | dept_id |
---|---|---|---|---|---|---|