Skip to main content

SQL INSERT Statement

SQL INSERT Statement

The SQL INSERT statement is used to insert new records or rows into a table in a database.


1. Basic Syntax

The basic syntax of the INSERT statement is:

INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);

Example:

// Example of inserting a new record into the "employees" table
INSERT INTO employees (first_name, last_name, age)
VALUES ('John', 'Doe', 30);

This example inserts a new record into the "employees" table with values for the "first_name", "last_name", and "age" columns.


2. Inserting Multiple Rows

You can insert multiple rows into a table using a single INSERT statement:

// Example of inserting multiple records into the "employees" table
INSERT INTO employees (first_name, last_name, age)
VALUES ('Jane', 'Smith', 25),
       ('Michael', 'Johnson', 35),
       ('Emily', 'Williams', 28);

This example inserts multiple records into the "employees" table with values for the specified columns.


3. Conclusion

The INSERT statement is essential in SQL for adding new records to a table in a database. It allows developers to insert single or multiple rows at once, providing flexibility when populating tables with data.

Comments