By using SQL DELETE command rows can be deleted from an existing table taking into account the given condition.
Conceptual
figure
Delete proclamation can be utilized to delete one or more row from a table. Filtering condition can be used for deleting selective data.
Syntax
Delete from <table_name> where <condition>;
Table_name => Any accurate table.
condition =>condition is a logic to get a specific record.
Examples
By viewing the below example, the concept of delete command can be easily understood.
[c]sql> select * from employee;
+--------+-------+-------+
| emp_id | ename | sal |
+--------+-------+-------+
| 1001 | maddi | 12000 |
| 1002 | jack | 13100 |
+--------+-------+-------+
2 rows in set (0.00 sec)
sql> delete from employee where ename='maddi';
Query OK, 1 row affected (0.16 sec)
sql> select * from employee;
+--------+-------+-------+
| emp_id | ename | sal |
+--------+-------+-------+
| 1002 | jack | 13100 |
+--------+-------+-------+
1 row in set (0.00 sec)
sql> delete from employee where emp_id=1001;
Query OK, 1 row affected (0.16 sec)
sql> select * from employee;
+--------+-------+-------+
| emp_id | ename | sal |
+--------+-------+-------+
| 1002 | jack | 13100 |
+--------+-------+-------+
1 row in set (0.00 sec)[/c]
The above example tells that, when delete command is performed on a table employee and wants to delete ename=maddi, then it delete the entire details of maddi and gives the output of remaining employees in the table.And in another example when delete command is performed on emp_id=1001,then it will delete all the rows of that emp_id like emp_id,ename and salary field names.
Difference between Truncate and Delete Statements
Description
The difference between truncate and delete statements is as follows:
TRUNCATE deletes all the records from the table but DELETE can be used to delete selective records.
TRUNCATE releases memory occupied by the data but DELETE does not do that.
Data removing by TRUNCATE cannot be recovered but data deleted using DELETE can be recovered.
Summary
Key Points
SQL DELETE - Delete proclamation is utilized to erase a particular column value from the table.