Structured Query Language/DELETE 1
Tools
General
Sister projects
In other projects
| Structured Query Language DELETE 1 | DELETE 2 |
Hint: Be careful and deactivateAUTOCOMMIT.
The DELETE command removes rows from a table.
DELETEFROM<tablename>WHERE<search_condition>;
The syntax is straightforward as we do not need to specify any column name - rows are deleted as a whole and not partly. As usual, the search condition specifies the criterion which identifies the affected rows. It can involve zero, one, or more rows. If we omit the WHERE keyword and the search conditionall rows are affected.
-- Delete one rowDELETEFROMpersonWHERElastname='Burton';-- It's only a test. Restore the row.ROLLBACK;
The information about Mr. Burton was deleted and restored again.
We present some more information about the DELETE commandhere. There are also some comments to the interconnection with theTRUNCATE command.
Delete the hobby 'Yoga'.
-- Delete one rowDELETEFROMhobbyWHEREhobbyname='Yoga';-- or: WHERE id = 6;ROLLBACK;-- if we want to restore the rowCOMMIT;-- if we want to commit our work-- Check the resultSELECT*FROMhobby;
Delete all relations between persons and hobbies. Check result. Restore all rows.
-- compact syntax - great impactDELETEFROMperson_hobby;-- Check the resultSELECT*FROMperson_hobby;-- restore everythingROLLBACK;
| Structured Query Language DELETE 1 | DELETE 2 |