Home / Learn React / SQL Basics: CREATE, INSERT, SELECT, UPDATE, DELETE
SQL Basics: CREATE, INSERT, SELECT, UPDATE, DELETE
SQL is the language of the database. Five commands cover almost everything a React app needs.
Theory in plain words
What it is
SQL (Structured Query Language) is how you talk to a relational database. Data lives in tables made of columns (the fields) and rows (the records).
Why we use it
A table is much safer and faster than a text file or localStorage. The database enforces types, unique values and links between tables, and it can search millions of rows in milliseconds.
How it works
You write a statement such as SELECT title FROM notes WHERE done = 0. MySQL finds the matching rows and returns them as a result table. PHP turns that table into JSON for React.
Where it is used
- MySQL and MariaDB on Hostinger
- phpMyAdmin, where you can type SQL and see the tables
- Every PHP, Node or Python backend that stores data
Create a table
CREATE TABLE notes (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(200) NOT NULL,
done TINYINT(1) NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;PRIMARY KEYmakes each row unique.AUTO_INCREMENTgives 1, 2, 3 automatically.NOT NULLmeans the value is required.utf8mb4stores every language and emoji correctly.
| Type | Use for | Example |
|---|---|---|
| INT | whole numbers, ids | 42 |
| DECIMAL(10,2) | money | 199.50 |
| VARCHAR(n) | short text up to n characters | a title |
| TEXT | long text | a note body |
| TINYINT(1) | true or false | 0 or 1 |
| DATE, DATETIME, TIMESTAMP | time | 2026-11-25 10:30:00 |
Insert and select
INSERT INTO notes (title) VALUES ('Buy milk'), ('Learn SQL');
SELECT * FROM notes;
SELECT id, title FROM notes WHERE done = 0 ORDER BY id DESC LIMIT 10;The result of the second SELECT is a table with only the columns you asked for:
| id | title |
|---|---|
| 2 | Learn SQL |
| 1 | Buy milk |
Update and delete
UPDATE notes SET done = 1 WHERE id = 1;
DELETE FROM notes WHERE id = 2;WHERE with UPDATE and DELETE. DELETE FROM notes; removes every row. Test your WHERE with a SELECT first.Filtering operators
| You want | SQL |
|---|---|
| equal | WHERE done = 1 |
| not equal | WHERE done <> 1 |
| text contains | WHERE title LIKE '%sql%' |
| in a list | WHERE id IN (1, 3, 5) |
| range | WHERE price BETWEEN 10 AND 50 |
| missing value | WHERE user_id IS NULL |
| both | WHERE done = 0 AND title LIKE ... |
| count | SELECT COUNT(*) FROM notes |
The same idea in JavaScript
If you know filter, sort and slice you already know SELECT. This example shows both side by side.
MySQL does this work for you inside the database, so only the needed rows travel to PHP and then to React.
Quick quiz
1. What does UPDATE without WHERE do?
Without WHERE the change applies to all rows.
2. Which column setting gives 1, 2, 3 automatically?
AUTO_INCREMENT creates the next id.
Common questions
What does UPDATE without WHERE do?
Changes every row. Without WHERE the change applies to all rows.
Which column setting gives 1, 2, 3 automatically?
AUTO_INCREMENT. AUTO_INCREMENT creates the next id.