Overview
This lecture explains how to delete specific rows from a SQL table using the DELETE statement and emphasizes the importance of using the WHERE clause to avoid deleting all data unintentionally.
Deleting Rows from a Table
- Use the DELETE statement in SQL to remove rows from a table.
- The basic syntax is:
DELETE FROM airport;
- Running the statement without conditions deletes all rows from the airport table.
- To delete a specific row, add a WHERE clause (e.g.,
WHERE code = "MCO").
- The example deletes the row for Orlando International Airport, which has the code "MCO".
- After execution, only the row matching the condition is deleted, and the rest remain.
- If the specified condition matches no rows, zero rows are deleted.
- The action is irreversible; deleted data cannot be recovered through SQL.
Importance of the WHERE Clause
- Omitting the WHERE clause deletes every row in the table.
- The WHERE clause limits the DELETE action to specific rows, preventing accidental data loss.
- Always double-check the WHERE condition before running DELETE statements.
Key Terms & Definitions
- DELETE statement — SQL command used to remove rows from a table.
- WHERE clause — SQL condition that specifies which rows to affect in a statement.
- Irreversible — Once rows are deleted, they cannot be restored via SQL undo.
Action Items / Next Steps
- Watch the next video on altering tables and adding new columns.