This article covers how to Delete Data in SQL using the DELETE statement.
The SQL DELETE Query is used to delete the existing records from a table.
You can use the WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted.
In Structured Query Language, more commonly known as SQL, the DELETE statement is one of the most powerful operations available to users.
DELETE operations irreversibly delete one or more rows of data from a database table.
Being such a fundamental aspect of data management, it's important for SQL users to understand how the DELETE statement works.
The basic syntax of the DELETE query with the WHERE clause is as follows:
DELETE FROM table_name
You can combine N number of conditions using AND or OR operators.
Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement.
The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records in the table will be deleted!
To Delete All Records:
It is possible to delete all rows in a table without deleting the table. This means that the table structure, attributes, and indexes will be intact:
DELETE FROM table_name;
DROP is used to delete a whole database or just a table. The DROP statement destroys the objects like an existing database, table, index, or view. A DROP statement in SQL removes a component from a relational database management system (RDBMS).