Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

INSERT INTO



The SQL INSERT INTO Statement


The INSERT INTO statement in SQL is used to insert new records (rows) into a table. It allows you to specify the values to be inserted into specific columns or to insert data from a SELECT query.

Here's the basic syntax of the INSERT INTO statement:


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


Example:

Let's say we have a table named employees with columns employee_id, first_name, last_name, and salary, and we want to insert a new employee record:


INSERT INTO employees (employee_id, first_name, last_name, salary)
VALUES (101, 'John', 'Doe', 50000);


This will insert a new record into the employees table with the specified values for employee_id, first_name, last_name, and salary.

If you want to insert data into all columns of the table without specifying column names, you can omit the column list:


INSERT INTO employees
VALUES (102, 'Jane', 'Smith', 60000);


This assumes that the values provided are in the same order as the columns are defined in the table.

You can also use a SELECT query to insert data into a table from another table or query result:


INSERT INTO employees (employee_id, first_name, last_name, salary)
SELECT employee_id, first_name, last_name, salary
FROM temporary_employees;


This will insert records into the employees table by selecting data from the temporary_employees table.

Remember to ensure that the data types of the values being inserted match the data types of the columns in the table.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java