Skip to main content

SQL Create Read Update Delete (CRUD) operations

Create Table

CREATE TABLE users (id INT PRIMARY KEY AUTO_INCREMENT NOT NULL, name VARCHAR(100) NOT NULL, age INT);

Insert into a Table (C)

INSERT INTO users (name, age) VALUES (Andrei, 20), (Sally, 5);

Read (R)

SELECT name, age FROM users WHERE age = 20 AND name LIKE 'A%';

Update (U)

UPDATE users SET age = 30 WHERE name = 'Andrei';

Delete (D)

DELETE FROM users WHERE name = 'Sally';

Alter Table

ALTER TABLE users ADD height smallint;