SQL tutorial
SQL Delete
Learn more about SQL, a standard language for interacting with databases and storing, manipulating, and retrieving data from databases.
Go hands-on with SQL in our free interactive SQL tutorial.
In contrast to other commonly used statements that return, add, or modify data, the SQL DELETE
statement removes records from a table, provided the user has permissions to do so.
As such, unlike using a simple SELECT
statement or other queries, the SQL DELETE
statement should be used with considerable caution as its execution removes data from a database and is not reversible.
A SQL DELETE
statement in its simplest form would be as below:
DELETE FROM <table>;
This statement would delete all records in a table, leaving the table empty. Instead, a SQL DELETE
statement is almost always combined with a WHERE
clause specifying which data to delete based upon a condition or conditions that the rows must satisfy. In this case, a SQL DELETE
statement would take the general form:
DELETE FROM <table> WHERE <condition>;
For example, if we wanted to delete all rows in the employees
table where the gender of the employee is male, we could do so using the statement as below:
DELETE FROM employees WHERE gender = 'M';
As with UPDATE
and INSERT
statements, a SQL DELETE
statement will not return any data upon completion, only whether it was successful or unsuccessful in execution.
The DELETE
statement is useful for arranging data in ad hoc working tables but would likely not be required by a Data Analyst or Data Scientist working in a relational database otherwise; for a data engineer its usage might be much more common.
It should also be noted that in most organizations, the ability to execute a SQL DELETE
statement would likely be restricted to privileged users, given the potential for data loss.
Learn SQL Today
Get hands-on experience writing code with interactive tutorials in our free online learning platform.
- Free and fun
- Designed for beginners
- No downloads or setup required