Skip to main content
Advertisement

SQL: Data Manipulation (CRUD)

1. SELECT (Read)

Used to retrieve data.

-- Retrieve all columns
SELECT * FROM users;

-- Retrieve specific columns with conditions
SELECT name, email FROM users WHERE age >= 20;

-- Sorting and limiting the number of results
SELECT * FROM products ORDER BY price DESC LIMIT 5;

2. INSERT (Create)

Inserts new data into a table.

INSERT INTO users (name, email, age)
VALUES ('Hong Gil-dong', 'hong@example.com', 25);

3. UPDATE (Update)

Modifies existing data. Caution: If you omit the WHERE clause, all rows in the table will be updated.

UPDATE users SET age = 26 WHERE name = 'Hong Gil-dong';

4. DELETE (Delete)

Removes data from a table. Caution: If you omit the WHERE clause, all data in the table will be deleted.

DELETE FROM users WHERE id = 10;
Advertisement