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.

In shortCREATE TABLE makes the structure. INSERT adds rows. SELECT reads. UPDATE changes. DELETE removes. WHERE chooses which rows.

Theory in plain words

A SQL statementSQL textMySQL parses itFinds rowsResult table
A SQL statement

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
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;
TypeUse forExample
INTwhole numbers, ids42
DECIMAL(10,2)money199.50
VARCHAR(n)short text up to n charactersa title
TEXTlong texta note body
TINYINT(1)true or false0 or 1
DATE, DATETIME, TIMESTAMPtime2026-11-25 10:30:00

Insert and select

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:

idtitle
2Learn SQL
1Buy milk

Update and delete

UPDATE and DELETE
UPDATE notes SET done = 1 WHERE id = 1;
DELETE FROM notes WHERE id = 2;
Careful:Always write WHERE with UPDATE and DELETE. DELETE FROM notes; removes every row. Test your WHERE with a SELECT first.

Filtering operators

You wantSQL
equalWHERE done = 1
not equalWHERE done <> 1
text containsWHERE title LIKE '%sql%'
in a listWHERE id IN (1, 3, 5)
rangeWHERE price BETWEEN 10 AND 50
missing valueWHERE user_id IS NULL
bothWHERE done = 0 AND title LIKE ...
countSELECT 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.

SELECT ... WHERE ... ORDER BY ... LIMIT in JavaScriptTry it Yourself

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?

2. Which column setting gives 1, 2, 3 automatically?

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.