DELETE COMMAND IN SQL:
In SQL the delete command is used to delete the existing records from the table.
With the use of 'WHERE' Clause you can delete the specific records from the table.
Using delete command you can delete all the records from the table without deleting the table.
Syntax:
DELETE FROM table_name
WHERE condition;
Remember:
Be careful while deleting records in a table because all records in the table will be delete.
Example:
Employee table:
emp_id |
emp_name |
emp_Salary |
01 |
Namit |
20000 |
02 |
Peter |
35000 |
03 |
Tony |
55000 |
04 |
David |
26500 |
05 |
Greg |
40000 |
Condition Example:
DELETE FROM Employee
WHERE salary<30000
Result After Delete Condition implement:
emp_id |
emp_name |
emp_Salary |
02 |
Peter |
35000 |
03 |
Tony |
55000 |
05 |
Greg |
40000 |
Delete all record:
Syntax:
DELETE FROM table_name
or
DELETE * FROM table_name;
EXAMPLE:
DELETE FROM Employee;
emp_id |
emp_name |
emp_Salary |
|
|
|
Difference between truncate and delete:
|
DELETE |
TRUNCATE |
1 |
We can delete any specfic records in the table. |
We can not delete any specific records. |
2 |
Its DML Command. |
Its DDL Command. |
3 |
It is used for only temporary deletion. |
It is used for the permanent deletion. |