Introduction
Imagine you have a list of contacts on paper, and you want to add new friends, change phone numbers, or remove old contacts. Managing data in a database works similarly, and DML commands help you do these tasks easily.
Think of a notebook where you keep your friends' contact details. When you meet a new friend, you write their info down (INSERT). If they change their phone number, you cross out the old one and write the new number (UPDATE). If you lose touch, you erase their details (DELETE).
┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ INSERT │──────▶│ UPDATE │──────▶│ DELETE │ │ Add records │ │ Modify data │ │ Remove data │ └─────────────┘ └─────────────┘ └─────────────┘
CREATE TABLE contacts (id INT, name TEXT, phone TEXT); INSERT INTO contacts (id, name, phone) VALUES (1, 'Alice', '12345'); UPDATE contacts SET phone = '67890' WHERE id = 1; DELETE FROM contacts WHERE id = 1;
INSERT command adds new rows, UPDATE changes existing rows, and DELETE removes rows.UPDATE table_name SET column = value WHERE condition; to update specific rows.products with columns id, name, and price. What will be the result of this query?DELETE FROM products WHERE price < 100;
price < 100 correctly selects products priced below 100. The semicolon is optional in many systems but good practice.UPDATE employees SET salary = 6000 WHERE;
Pass the test and this pattern moves unknown