The Wayback Machine - https://web.archive.org/web/20240822190641/https://www.geeksforgeeks.org/sql-query-to-insert-multiple-rows/
Open In App

SQL Query to Insert Multiple Rows

Last Updated : 13 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Insertion in a table is a DML (Data manipulation language) operation in SQL. When we want to store data we need to insert the data into the database. We use the INSERT statement to insert the data into the database. 
 
In this article, we see how to insert individual as well as multiple rows in a database using the INSERT statement in the MSSQL server.

Creating a Database: Use the below command to create a database named GeeksforGeeks:

Query:

CREATE DATABASE GeeksforGeeks;

Output:

Using the Database: To use the GeeksforGeeks database use the below command:

Query:

USE GeeksforGeeks

Output:

Creating a Table: Create a table employee_details with  4 columns using the following SQL query: 

Query:

CREATE TABLE employee_details(
   emp_id VARCHAR(8),
   emp_name VARCHAR(20),
   emp_dept_id VARCHAR(20),
   emp_age INT);

Output:

Verifying the table: To view the description of the tables in the database using the following SQL query:

Query:

EXEC sp_columns employee_details;

Output:

The query for Inserting rows into the Table  :

Inserting rows into employee_details table using the following SQL query:

1. Inserting individual rows into the table :

Query:

INSERT INTO employee_details VALUES('E40001','PRADEEP','E101',36);
INSERT INTO employee_details VALUES('E40002','ASHOK','E102',28);
INSERT INTO employee_details VALUES('E40003','PAVAN KUMAR','E103',28); 

Output:

2. Viewing the inserted data:

Query:

SELECT * FROM employee_details;

Output:

3. Inserting multiple rows into the table:

Query:

INSERT INTO employee_details VALUES
  ('E40004','SANTHOSH','E102',25),
  ('E40005','THAMAN','E103',26),
('E40006','HARSH','E101',25),
  ('E40007','SAMHITH','E102',26);

Output:

4. Viewing the inserted data now:

Query:

SELECT * FROM employee_details;

Output:


Previous Article
Next Article

Similar Reads

SQL Query to Convert Rows to Columns in SQL Server
In this article we will see, how to convert Rows to Column in SQL Server. In a table where many columns have the have same data for many entries in the table, it is advisable to convert the rows to column. This will help to reduce the table and make the table more readable. For example, Suppose we have a table given below: NAMECOLLEGEROLL NUMBERSUB
2 min read
Insert Multiple Values Into Multiple Tables in SQL Server
To insert multiple values into multiple tables in SQL Server, use the OUTPUT clause. The SQL OUTPUT clause allows to insert multiple values into multiple tables in a single query. Output clause clause in SQL is used to capture data affected by Data Manipulation Language (DML) statements like INSERT, UPDATE, or DELETE. SyntaxSyntax to insert multipl
2 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
How to Insert Rows with NULL Values in SQL?
In SQL, due to lack of data, we sometimes need to insert rows with NULL values in the tables. Here, the keyword NULL(without quotes) is used to represent no data. There are some key points of Null value: NULL value is different from a zero value.A NULL value is used to represent a missing value, but that it usually has one of three different interp
2 min read
SQL Query for Finding Maximum Values in Rows
SQL stands for Structured Query Language and is used to create, maintain and retrieve the data from relational databases. Relational Database Management Systems (RDBMS) like MySQL, MS Access, Oracle, and SQL Server use SQL as their standard database language. Here we are going to see the SQL query for Finding Maximum Values in Rows. Let us understa
3 min read
SQL Query to Add Ranking Positions of Rows in a Database With RANK()
In this article, we will discuss the overview of SQL function RANK and then our main focus will be on Add Ranking Positions of Rows in a Database With RANK() in SQL. Let's discuss it one by one. Overview :Generally, when max/min commands are executed, a single row is displayed as output. RANK() is an SQL function introduced in order to rank the row
2 min read
SQL Query to Delete Duplicate Rows
As we know that duplicity in our database tends to be a waste of memory space. It records inaccurate data and is also unable to fetch the correct data from the database. In this article, we will learn how to delete duplicate rows from a database table.One or more rows that have identical or the same data value are considered to be Duplicate rows. T
2 min read
SQL Query to Update All Rows in a Table
The Update statement is a SQL keyword to update data in the database. We can update all the rows in the database or some values with the help of conditions. The update is a SQL keyword and it falls under Data Manipulation Language(DML), as the name suggests it is used to manipulate the data. There are many DML keywords that fall under this: UPDATEI
2 min read
SQL Query to DELETE Certain Rows Based on Comparisons with Other Tables
In this article, we will see, how to delete certain rows based on comparisons with other tables. We can perform the function by using a subquery in place of the condition in WHERE Clause. A subquery is a query that appears inside another query. It can also be called a nested query. Syntax: SELECT * FROM table_name WHERE column_name= ( SELECT column
2 min read
SQL Query to Return Rows Matching a Certain Condition
In SQL, sometimes we need to select matching a certain condition from the table. We will use the SELECT command along with the WHERE clause to apply a condition to achieve this in SQL. For this article. We will be using the Microsoft SQL Server as our database. Syntax: SELECT COLUMN_NAME_1, COLUMN_NAME_2, .... FROM TABLE_NAME WHERE CONDITION;Step 1
2 min read
SQL Query to Count the Number of Rows in a Table
In SQL, the COUNT() function is used to determine the total number of rows in a table, including those with NULL values. This aggregate function is essential for summarizing data and gaining insights into the size of a dataset. In this article, We will learn about the How to Count the Number of Rows in a Table in SQL. How to Count the Number of Row
4 min read
SQL Query to Add Email Validation Using Only One Query
In this article let us see how can we check for the validation of mails in the student database using MSSQL as the database server. For example, if the email is like abcdedfABCDEF...0123456@gmail.com this is the valid form of an email if it is other than this then that is said to Invalid. So, now we will discuss this concept in detail step-by-step:
2 min read
BULK INSERT in SQL Server(T-SQL command)
BULK INSERT in SQL Server(T-SQL command): In this article, we will cover bulk insert data from csv file using the T-SQL command in the SQL server and the way it is more useful and more convenient to perform such kind of operations. Let's discuss it one by one.  ConditionSometimes there is a scenario when we have to perform bulk insert data from .cs
3 min read
Removing Duplicate Rows (Based on Values from Multiple Columns) From SQL Table
In SQL, some rows contain duplicate entries in multiple columns(>1). For deleting such rows, we need to use the DELETE keyword along with self-joining the table with itself. The same is illustrated below. For this article, we will be using the Microsoft SQL Server as our database. Step 1: Create a Database. For this use the below command to crea
3 min read
SQL Query to Exclude Multiple Values
To exclude multiple values to be fetched from a table we can use multiple OR statements but when we want to exclude a lot of values it becomes lengthy to write multiple AND statements, To avoid this we can use the NOT IN clause with the array of values that need to be excluded with the WHERE statement. In this article let us see the SQL query to ex
2 min read
SQL Query for Matching Multiple Values in the Same Column
In SQL, for matching multiple values in the same column, we need to use some special words in our query. Below, 3 methods are demonstrated to achieve this using the IN, LIKE and comparison operator(>=). For this article, we will be using the Microsoft SQL Server as our database. Step 1: Create a Database. For this use the below command to create
2 min read
How to Get Multiple Counts With One SQL Query?
In database management efficiency is key. SQL operations from data retrieval to manipulation, need to be optimized to ensure smooth processing. One common requirement is the need to obtain multiple counts from the table based on different conditions. While it's logical to execute separate queries, SQL provides a more elegant solution of obtaining m
5 min read
How to Update Multiple Records Using One Query in SQL Server?
To update multiple records in the SQL server, use the UPDATE Statement. Using the SQL UPDATE statement with the WHERE clause users can update multiple records in the table based on some condition. There can be two cases in this situation: Table of Content Update Multiple Records Based on One Condition in SQL ServerUpdate Multiple Records Based on M
4 min read
SQL Query to Check if Date is Greater Than Today in SQL
In this article, we will see the SQL query to check if DATE is greater than today's date by comparing date with today's date using the GETDATE() function. This function in SQL Server is used to return the present date and time of the database system in a ‘YYYY-MM-DD hh:mm: ss. mmm’ pattern. Features: This function is used to find the present date a
2 min read
SQL Query to Add a New Column After an Existing Column in SQL
Structured Query Language or SQL is a standard Database language that is used to create, maintain and retrieve data from relational databases like MySQL, Oracle, SQL Server, Postgres, etc. In Microsoft SQL Server, we can change the order of the columns and can add a new column by using ALTER command. ALTER TABLE is used to add, delete/drop or modif
3 min read
SQL - SELECT from Multiple Tables with MS SQL Server
In SQL we can retrieve data from multiple tables also by using SELECT with multiple tables which actually results in CROSS JOIN of all the tables. The resulting table occurring from CROSS JOIN of two contains all the row combinations of the 2nd table which is a Cartesian product of tables. If we consider table1 contains m rows and table2 contains n
3 min read
Configure SQL Jobs in SQL Server using T-SQL
In this article, we will learn how to configure SQL jobs in SQL Server using T-SQL. Also, we will discuss the parameters of SQL jobs in SQL Server using T-SQL in detail. Let's discuss it one by one. Introduction :SQL Server Agent is a component used for database task automation. For Example, If we need to perform index maintenance on Production ser
7 min read
Insert Into Select statement in MS SQL Server
Prerequisites - Insert statement in MS SQL Server, Select statement in MS SQL Server Consider a university database. There are two tables namely Student and Marks. In case, the marks of a few students has to be transferred from the marks table to the marks table, there are many ways to do so. One can use subqueries (query nested in another query) b
2 min read
Capturing INSERT Timestamp in Table SQL Server
While inserting data in tables, sometimes we need to capture insert timestamp in the table. There is a very simple way that we could use to capture the timestamp of the inserted rows in the table. Capture the timestamp of the inserted rows in the table with DEFAULT constraint in SQL Server. Use DEFAULT constraint while creating the table: Syntax: C
2 min read
Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
In this article, we will be learning about how to do basic database operations using JDBC (Java Database Connectivity) API in Java programming language. These basic operations are INSERT, SELECT, UPDATE, and DELETE statements in SQL language. Although the target database system is Oracle Database, the same techniques can be applied to other databas
6 min read
SQL | INSERT IGNORE Statement
We know that a primary key of a table cannot be duplicated. For instance, the roll number of a student in the student table must always be distinct. Similarly, the EmployeeID is expected to be unique in an employee table. When we try to insert a tuple into a table where the primary key is repeated, it results in an error. However, with the INSERT I
2 min read
SQL INSERT INTO SELECT Statement
In SQL, the INSERT INTO statement is used to add or insert records to the specified table. We can use this statement to add data directly to the table. We use the VALUES keyword along with the INSERT INTO statement. VALUES keyword is accompanied by column names in a specific order in which we want to insert values in them. SELECT statement is used
5 min read
How to Insert a Line Break in a SQL VARCHAR
In SQL, VARCHAR and NVARCHAR are widely used data types for storing character data. It may sometimes be necessary to insert line breaks into these string values ​​for better readability or to display the information in a formatted manner. Although SQL itself does not have a specific newline character, there are methods to achieve this. In this arti
3 min read
How to fix Cannot Insert Explicit Value For Identity Column in Table in SQL
In SQL, the error message "Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF" is a common issue encountered when attempting to insert explicit values into an identity column in a table. This error occurs because SQL, by default, does not allow explicit values to be inserted into identity columns un
7 min read
How to get the insert ID in SQL?
In the world of databases, having a clear understanding of primary keys is essential to maintaining data accuracy and ensuring efficient data retrieval. A primary key is a unique identifier for each record in a table and plays a critical role in database design. In SQL databases, obtaining the insert ID after adding a new record to a table is a com
4 min read
Article Tags :
three90RightbarBannerImg