Perform database query operations (create, update, delete)
10 Database and File Concepts – Query Operations
Create (INSERT) 📥
Imagine you’re adding a new student to a class roster. In a database, you do the same with an INSERT statement.
- Choose the table (e.g.,
students). - Specify the columns you’re adding data to.
- Provide the values for each column.
- Execute the statement.
| SQL Syntax | Example |
|---|---|
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
|
INSERT INTO students (id, name, age) VALUES (101, 'Alice', 15);
|
Exam Tip: Remember that
INSERT can also be used with SELECT to copy rows from one table to another. Practice writing both simple and multi-row inserts.
Update (UPDATE) ✏️
Updating is like correcting a typo in a student’s phone number. Use UPDATE to modify existing data.
- Select the table to update.
- Define the new values with
SET. - Specify which rows to change with
WHERE(never forget theWHEREclause unless you want to change everything!). - Execute the statement.
| SQL Syntax | Example |
|---|---|
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
|
UPDATE students SET age = 16 WHERE id = 101;
|
Exam Tip: Practice writing
UPDATE statements that change multiple columns at once and use complex WHERE conditions (e.g., WHERE age > 15 AND name LIKE 'A%').
Delete (DELETE) 🗑️
Deleting is like removing a student who has left the school. Use DELETE to remove rows.
- Select the table from which to delete.
- Specify the rows to remove with
WHERE(again, never forget it!). - Execute the statement.
| SQL Syntax | Example |
|---|---|
DELETE FROM table_name WHERE condition;
|
DELETE FROM students WHERE id = 101;
|
Exam Tip: When writing
DELETE statements, double‑check the WHERE clause. A missing clause will delete all rows in the table!
Quick Reference Cheat‑Sheet
| Operation | Key Clause | Remember |
|---|---|---|
| INSERT | VALUES |
Always list columns in the same order as values. |
| UPDATE | SET |
Never omit WHERE unless you mean to update all rows. |
| DELETE | WHERE |
Missing WHERE deletes everything – a common exam trap. |
Final Exam Reminder: Practice writing full
INSERT, UPDATE, and DELETE statements from scratch. Pay special attention to syntax, punctuation, and the WHERE clause. Good luck! 🚀
Revision
Log in to practice.
1 views
0 suggestions