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:
id | name | signup_date | |
---|---|---|---|
4 | Laura Adams | laura.adams@example.com | 2023-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.
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.