Difference between revisions of "Delete Queries"
(→Basic Quiz) |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | Used for deleting rows from a table. | + | Used for deleting rows from a table. The where section should give the criteria for deleting records, for example the specific ID for the record could be used. Alternatively the criteria could be more complex and use multiple criteria. |
<syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
− | DELETE FROM table WHERE column1=value1; | + | DELETE FROM table WHERE column1=value1; |
</syntaxhighlight> | </syntaxhighlight> | ||
Line 8: | Line 8: | ||
<syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
− | DELETE FROM table WHERE column1=value1 AND column2=value2; | + | DELETE FROM table WHERE column1=value1 AND column2=value2; |
</syntaxhighlight> | </syntaxhighlight> | ||
+ | ==Notes== | ||
* Not specifying which records to delete will result in every record being deleted | * Not specifying which records to delete will result in every record being deleted | ||
:*The same can be achieved with 'DELETED * FROM table' | :*The same can be achieved with 'DELETED * FROM table' | ||
* This process cannot be undone | * This process cannot be undone | ||
* Not to be confused with DROP, for deleting columns and tables. | * Not to be confused with DROP, for deleting columns and tables. | ||
+ | |||
+ | ===Basic Quiz=== | ||
+ | All these questions will use this table called Employees: | ||
+ | |||
+ | [[File:Capture.png]] | ||
+ | <quiz display=simple> | ||
+ | {which is the command to remove a record from a table: | ||
+ | |||
+ | |||
+ | |type="()"} | ||
+ | - Drop Record | ||
+ | ||Incorrect | ||
+ | - Remove Record | ||
+ | ||Incorrect | ||
+ | + Delete From | ||
+ | ||Correct | ||
+ | - Delete Record' | ||
+ | ||Incorrect | ||
+ | |||
+ | {which of the following will successfully delete the record for 'Wonder Woman': | ||
+ | |||
+ | |||
+ | |type="()"} | ||
+ | - Delete From Employees Where 'First Name' = 'Wonder' , 'Last Name' = 'Woman' | ||
+ | ||Incorrect | ||
+ | - Delete From Employees Where 'Name' = 'Wonder Woman' | ||
+ | ||Incorrect | ||
+ | - Delete From Employees Where 'Last Name' = 'Woman' | ||
+ | ||Incorrect | ||
+ | + Delete From Employees Where 'First Name' = 'Wonder' And 'Last Name' = 'Woman' | ||
+ | ||Correct | ||
+ | |||
+ | |||
+ | </quiz> |
Latest revision as of 10:38, 28 September 2020
Used for deleting rows from a table. The where section should give the criteria for deleting records, for example the specific ID for the record could be used. Alternatively the criteria could be more complex and use multiple criteria.
DELETE FROM table WHERE column1=value1;
or:
DELETE FROM table WHERE column1=value1 AND column2=value2;
Notes
- Not specifying which records to delete will result in every record being deleted
- The same can be achieved with 'DELETED * FROM table'
- This process cannot be undone
- Not to be confused with DROP, for deleting columns and tables.
Basic Quiz
All these questions will use this table called Employees: