SQL DELETE Statement
SQL DELETE Statement
To eliminate rows from a table, using the SQL DELETE statement. Depending on certain criteria, it permits the deletion of one or more records. If the WHERE
clause is not included, all records in the table will be removed.
Complete Python Course with Advance topics:-Click Here
SQL Tutorial :-Click Here
SQL DELETE Syntax
The syntax for the SQL DELETE statement is as follows:
DELETE FROM table_name [WHERE condition];
table_name
: The name of the table from which records are to be deleted.WHERE condition
: Specifies which rows should be deleted. If omitted, all rows will be deleted.
SQL DELETE Example
Consider a table named STUDENT:
ID | STUDENT_NAME | CITY | GRADE |
---|---|---|---|
201 | Aryan Verma | Lucknow | A |
202 | Riya Sharma | Bhopal | B+ |
203 | Karan Mehta | Jaipur | A- |
204 | Neha Gupta | Mumbai | B |
Deleting a Specific Record
To delete a record where ID = 201
:
DELETE FROM STUDENT WHERE ID=201;
Resulting Table:
ID | STUDENT_NAME | CITY | GRADE |
---|---|---|---|
202 | Riya Sharma | Bhopal | B+ |
203 | Karan Mehta | Jaipur | A- |
204 | Neha Gupta | Mumbai | B |
Deleting All Records
To remove all records from the table:
DELETE FROM STUDENT;
Resulting Table:
ID | STUDENT_NAME | CITY | GRADE |
---|---|---|---|
This deletes all rows from the STUDENT table.
Importance of WHERE Clause in DELETE Statement
The WHERE
clause is crucial in the DELETE statement as it prevents unintended deletion of all records. Omitting WHERE
may result in the loss of all data in the table.
Invalid DELETE Statement in ORACLE
In Oracle, using *
in the DELETE statement is invalid:
DELETE * FROM STUDENT;
This will result in an error. Instead, use:
DELETE FROM STUDENT;
Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE
This guide provides a clear understanding of the SQL DELETE statement and its best practices. For more detailed SQL tutorials, visit UpdateGadh!
Post Comment