Lecture

INSERT INTO

The INSERT INTO statement is used to add new records to an existing table in SQL. Each new row you insert becomes a part of the table's dataset.


Basic Syntax

The example below shows how to insert a new row into a table using the INSERT INTO statement:

Insert a new row into a table
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
  • table_name is the name of the table.
  • (column1, column2, ...) lists the columns you want to insert data into.
  • VALUES (...) provides the values to store.

Please note that the number of values you provide must match the number of columns specified in the column list.


INSERT INTO Example

The query below adds a new row for a client named Laura Adams.

Insert a client into the clients table
INSERT INTO clients (id, name, email, signup_date) VALUES (4, 'Laura Adams', 'laura.adams@example.com', '2023-03-05');

The result will be:

idnameemailsignup_date
4Laura Adamslaura.adams@example.com2023-03-05

Insert Without Column List

If you provide values for all columns in the correct order, you can omit the column list:

Insert using default column order
INSERT INTO clients VALUES (5, 'Jason Green', 'jason.green@example.com', '2023-12-14');

Be careful: this only works if you supply values for every column in the correct sequence.


What's Next?

In the next lesson, you'll learn how to update existing data using the UPDATE command.

Quiz
0 / 1

What is the purpose of the INSERT INTO statement in SQL?

To remove rows from a table

To update data in an existing row

To add a new row to a table

To select specific rows from a table

Lecture

AI Tutor

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Tables

Execution Result