Database Basic SQL Queries Filtering Data Working with Functions Joining Tables Subqueries Modifying Data Advanced Queries Transactions and Locking Indexing and Optimization SQL Best Practices

INSERT Statement

The INSERT statement is used to insert new records in a table. The INSERT INTO statement is used to specify the table name where data will be inserted.

Syntax

INSERT INTO table_name (column1, column2, column3, ...)

VALUES (value1, value2, value3, ...);

Example

id name age
1 John 25
2 Smith 30

INSERT INTO employees (id, name, age)

VALUES (3, 'Doe', 35);

id name age
1 John 25
2 Smith 30
3 Doe 35

UPDATE Statement

The UPDATE statement is used to modify the existing records in a table. The UPDATE statement is used to specify the table name where data will be updated.

Syntax

UPDATE table_name

SET column1 = value1, column2 = value2, ...

WHERE condition;

Example

id name age
1 John 25
2 Smith 30

UPDATE employees

SET age = 35

WHERE name = 'John';

id name age
1 John 35
2 Smith 30

DELETE Statement

The DELETE statement is used to delete existing records in a table. The DELETE statement is used to specify the table name where data will be deleted.

Syntax

DELETE FROM table_name

WHERE condition;

Example

id name age
1 John 25
2 Smith 30

DELETE FROM employees

WHERE name = 'John';

id name age
2 Smith 30