Unit 3 Database - Implementation - SQL DELETE Flashcards
What is the purpose of the DELETE keyword in SQL?
The DELETE keyword is used to delete rows in a table.
What is the basic syntax for a DELETE statement?
DELETE FROM table_name WHERE condition;
Why is the WHERE clause important in a DELETE statement?
The WHERE clause specifies which rows to delete. Without it, all rows in the table will be deleted.
Example: How would you delete a user with userid = 7914?
DELETE FROM user WHERE userid = 7914;
How do you delete rows based on text values?
Use the DELETE statement with a WHERE clause that matches text values.
Example: Delete all hairdressers working at ‘West Style’ salon.
DELETE FROM hairdresser WHERE salon = ‘West Style’;
How do you delete rows based on numeric values?
Use the DELETE statement with a WHERE clause that matches numeric conditions.
Example: Delete all clients with hairdresserid = 2210.
DELETE FROM client WHERE hairdresserid = 2210;
What are cascade deletes in SQL?
Cascade deletes automatically delete related foreign key rows when a primary key row is deleted.
What happens if your RDBMS does not support cascade deletes?
You must manually delete related foreign key rows using additional DELETE statements.
Example: Delete a hairdresser with hairdresserid = 3030 and its related clients.
DELETE FROM hairdresser WHERE hairdresserid = 3030; DELETE FROM client WHERE hairdresserid = 3030;
How do you delete rows based on multiple conditions using AND?
Use the AND operator in the WHERE clause to specify multiple conditions.
Example: Delete all clients with clientid between 15000 and 17500.
DELETE FROM client WHERE clientid > 15000 AND clientid < 17500;
How do you delete rows based on multiple conditions using OR?
Use the OR operator in the WHERE clause to specify multiple conditions.
Example: Delete clients with clientid = 32100 or clientid = 40292.
DELETE FROM client WHERE clientid = 32100 OR clientid = 40292;
What precaution should you take before running a DELETE statement?
Run a SELECT query with the same WHERE clause to verify which records will be deleted.
What happens if you omit the WHERE clause in a DELETE statement?
All rows in the table will be deleted.
How can you check if rows were successfully deleted?
Use an appropriate SELECT query to confirm that the data has been removed.