In SQL, the DELETE Query removes existing records from a table. Depending on the condition specified in the WHERE clause, we can delete a single record or multiple records.
NOTE: This command must be used with extreme caution because it permanently deletes the data.
Syntax:
DELETE FROM table_name [WHERE condition];
where table_name is the table that has to be deleted, the WHERE clause in SQL DELETE statement is optional here.
Let’s take an example of student table:
ROLL | NAME | SEMESTER | YEAR |
---|---|---|---|
1 | RAMESH | 5 | 3 |
2 | SUJIT | 2 | 1 |
3 | SURESH | 1 | 1 |
4 | SUJIT | 7 | 4 |
DELETE FROM student;
The given query will delete all the records from the student table, as we haven’t mentioned any conditions for deletion.
DELETE FROM student WHERE NAME="SUJIT";
The above query will delete two records from the above table as there are two students with the name “SUJIT“.
Output:
ROLL | NAME | SEMESTER | YEAR |
---|---|---|---|
1 | RAMESH | 5 | 3 |
3 | SURESH | 1 | 1 |
TRUNCATE and DELETE are both SQL commands for removing data from a table, but they have some key differences:
Note: also read about SQL: UPDATE Query
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…