The Delete query in SQL only deletes records from the table, and it doesn’t make any changes in the definition, i.e., it only manipulates. Hence, it is DML (Data Manipulation Language). The Truncate command in SQL removes all rows from a table, i.e., it reinitializes the identity by making changes in the data definition. That’s the reason it is a DDL (Data Definition Language).
Let’s discuss in detail on:
The Delete query in SQL is basically used to delete or remove one or more existing records from a table. It is used along with the Where clause. Though, the Where condition is optional in the Delete query.
DELETE FROM table_name [WHERE condition];
where DELETE, FROM, and WHERE are the keywords and table_name is the name of the table. And in condition section, a condition is given, followed by a semicolon.
Let’s use the Delete command in SQL and delete the record of an employee whose age is 33 years
DELETE FROM employee WHERE e_age = 33;
Let’s delete a record with a condition where the name of the employee is sam
DELETE FROM employee WHERE e_name = ‘sam’;
SELECT * from employee;
The Truncate in SQL deletes all of the data inside a table. This command removes all records of the table but and retains the structure of the table
TRUNCATE TABLE table_name;
where TRUNCATE TABLE is the keyword and table_name is the name of the table, followed by a semicolon.
TRUNCATE TABLE employee;
SELECT * FROM employee
Well, this how we work with Delete query in SQL and where to use Truncate command in SQL. The table below gives a quick difference between these two commands.
This bring us to end of this part of tutorial where we learned how delete and truncate command in SQL. Here we learned how to delete column in SQL, how to delete row in SQL and how to delete table in SQL, and we learned how to use truncate table in SQL.Previous Next
Download Interview Questions asked by top MNCs in 2019?