Deleting Data
The DELETE statement deletes the specified record/row from the specified table.Syntax:
DELETE FROM table_name WHERE some_column = some_value;The above syntax is just one way to represent this statement. The "where" clause can contain any combination of operators and as many conditions as needed. The omition of the "where" clause causes all the records in the table to be deleted since it's the "where" clause which specifies which records have to be deleted. So be careful !!
Example:
| ssn | fname | lname | address | city | state |
|---|---|---|---|---|---|
| 512687458 | Joe | Smith | 83 First Street | Howard | Ohio |
| 758420012 | Mary | Scott | 842 Vine Ave. | Losantiville | Ohio |
| 102254896 | Sam | Jones | 33 Elm St. | Paris | New York |
| 876512563 | Sarah | Ackerman | 440 U.S. 110 | Upton | Michigan |
Suppose we want to delete the record of Joe Smith. The query for the same would be:
DELETE FROM Emp_Add WHERE fname = 'Joe' AND lname = 'Smith';The resultant table will be:
| ssn | fname | lname | address | city | state |
|---|---|---|---|---|---|
| 758420012 | Mary | Scott | 842 Vine Ave. | Losantiville | Ohio |
| 102254896 | Sam | Jones | 33 Elm St. | Paris | New York |
| 876512563 | Sarah | Ackerman | 440 U.S. 110 | Upton | Michigan |
This SQL query will delete all the records that have fname as Joe and lname as Smith. Had there been another row having the same fname and lname, it would have been deleted as well. In case you forget to put the WHERE clause, all the records in the Emp_Add table will be deleted. So be careful. !!
