Beginner
Question 1
Add a row to the users table with id=16, name='新田 一郎', email='nitta@example.com', city='札幌' (these are Japanese name/city values matching this table's existing data), then view all the data.
📖 ExplanationReference
What is DML?
SQL statements that manipulate data are collectively called DML (Data Manipulation Language). INSERT, UPDATE, and DELETE are the three basics.
Adding data with INSERT
To add new data to a table, use INSERT INTO. The list of column names and the list of values must line up in the same order.
INSERT INTO users (id, name, email, city)
VALUES (16, '新田 一郎', 'nitta@example.com', '札幌');
-- '新田 一郎' is a Japanese name, '札幌' is "Sapporo" — matching this table's existing Japanese data
Updating data with UPDATE
To update existing data, use UPDATE.
UPDATE products
SET price = 100000
WHERE id = 1;
⚠️ UPDATE/DELETE without WHERE is the most dangerous mistake you can make
Write
In real-world work, always make a habit of running a
Write
UPDATE products SET price = 0; and every product's price becomes 0. Write DELETE FROM users; and every user is gone.In real-world work, always make a habit of running a
SELECT to confirm the target rows before you make any change.
Deleting data with DELETE
To delete data, use DELETE FROM.
DELETE FROM users
WHERE id = 16;
A safe order of operations
-- ① First, confirm the target with SELECT (important!)
SELECT * FROM users WHERE id = 16;
-- ② If it looks right, insert
INSERT INTO users (id, name, email, city) VALUES (16, '新田 一郎', 'nitta@example.com', '札幌');
-- ③ Confirm
SELECT * FROM users;
-- ④ Update
UPDATE users SET city = '仙台' WHERE id = 16;
-- ⑤ Delete
DELETE FROM users WHERE id = 16;
💼 Where it's used in the real world
User registration, updating product information, account closure processing — almost every application backend runs on INSERT, UPDATE, and DELETE. To avoid operational mistakes on production databases, many teams use transactions (
User registration, updating product information, account closure processing — almost every application backend runs on INSERT, UPDATE, and DELETE. To avoid operational mistakes on production databases, many teams use transactions (
BEGIN...COMMIT) to review changes before committing them.