Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Structured Query Language/DELETE 1

From Wikibooks, open books for an open world
<Structured Query Language
UPDATE 2Structured 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.

Example

[edit |edit source]
-- Delete one rowDELETEFROMpersonWHERElastname='Burton';-- It's only a test. Restore the row.ROLLBACK;

The information about Mr. Burton was deleted and restored again.

Further Information

[edit |edit source]

We present some more information about the DELETE commandhere. There are also some comments to the interconnection with theTRUNCATE command.

Exercises

[edit |edit source]

Delete the hobby 'Yoga'.

Click to see solution
-- 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.

Click to see solution
-- compact syntax - great impactDELETEFROMperson_hobby;-- Check the resultSELECT*FROMperson_hobby;-- restore everythingROLLBACK;


UPDATE 2Structured Query Language
DELETE 1
DELETE 2
Retrieved from "https://en.wikibooks.org/w/index.php?title=Structured_Query_Language/DELETE_1&oldid=4420794"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp