SQL
[Basic Grammar] SQL DELETE Statement
grace21110
2023. 10. 14. 11:59
반응형
The DELETE statement is used to remove existing records in a table.
- DELETE Syntax
DELETE FROM table_name WHERE condition;
** WARNING: Be careful when you delete records in a table! If you omit the WHERE clause, all records in the table will be deleted. The Where clause in the DELETE statement. **
Example
Delete the customer "Jack Lee" from the "Customers" table:
DELETE FROM Customers WHERE CustomerName = 'Jack Lee';
- Delete all the records
You can delete all rows in a table without deleting the table.
Example
Delete all rows in the "Students" table, without deleting the table:
DELETE FROM Students;
- Delete a table
When you want to delete the whole table, use the DROP TABLE statement:
Example
Remove the Brands table:
DROP TABLE Brands;
Exercises
Delete all the records from the "Orders" table where the "Status" value is 'Canceled'.
DELETE FROM Orders
WHERE Status = 'Canceled';