×

SQL Insert multiple rows

This article will deal with a new insertion method in SQL which inserts multiple rows at a time.

Multiple records can be inserted at a time into a specific table with a single Insert into values statement. Observe the below examples to clarify how multiple records are inserted into a specific table.

Examples of Inserting Multiple Rows

Example 1: Let us create a table named student which holds all the basic details of students like student_id, and student_name, and insert multiple records into it.

CREATE TABLE student(
student_id INT(50),  
student_address VARCHAR(100),
 );

Let us insert data into this table by an insert into the command

INSERT INTO student VALUES
(51,’ 600354 Panipat Haryana’),
(52, ‘500012 Hyderabad Telangana’),
(53, ‘799232 Cochin Kerala’),
(54, ‘899432, Madurai, Tamil Nadu’),
(55, ‘500072 Hyderabad Telangana’),
(56,’400034 Vizag Andhra Pradesh),
(57,’600043 Gurgram Haryana’),
(58, ‘394234 Vijaywada Andhra Pradesh’),
(59, ‘147653 Bhopal Madhya Pradesh’),
(60, ‘209431 Lucknow Uttar Pradesh’);
 

We can check the data of table by using the following command:

SELECT * FROM student;

The table will look like this:

Output:

student_idstudent_address
51600354 Panipat Haryana
52500012 Hyderabad Telangana
53799232 Cochin Kerala
54899432  Madurai Tamil Nadu
55500072 Hyderabad Telangana
56400034 Vizag Andhra Pradesh
57600043 Gurgram Haryana
58394234 Vijayawada Andhra Pradesh’
59147653 Bhopal Madhya Pradesh
60209431 Lucknow Uttar Pradesh’

Example 2:

Let us create a table called saletime which consists of customer time, product time, and the time at which the sale happened.

CREATE TABLE Saletime(
	ProductName VARCHAR(205),
	CustomerName VARCHAR(205),
	DispatchTimeStamp VARCHAR(205),
	Price INT,
	Location VARCHAR(205)
);
INSERT INTO Saletime VALUES
('Mouse', 'Altaf', TIMESTAMP('2020-04-04', '12:02:25.247552'), 1000, 'Nizamabad'),
 ('Laptop’, 'Pradeep', TIMESTAMP('2019-08-06', '04:33:22.721521'), 60000, 'Hyderabad'),
 ('Wireless_keyboard', 'Bhanu', TIMESTAMP('2016-02-27', '04:20:27.263420'), 2000, 'Vijayawada'),
 ('Mobile', 'Vani', TIMESTAMP ('2018-05-22', '10:20:25.265563'), 10000, 'Cochin’),
('Headset', 'Ram', TIMESTAMP('2022-02-20', '11:39:37.522321'), 5000, 'Delhi'),
('Earphones', 'Rahim' , TIMESTAMP('2021-11-29', '09:19:23.432356'), 2000, 'Lucknow'),
 ('Harddisk', 'Charan' , TIMESTAMP('2019-12-30', '12:54:25.122386'), 7000, 'Bangalore');

We can check the data of table by using the following command:

SELECT * FROM Saletime;

The table will look like this:

Output:

ProductNameCustomerNameDispatchTimeStampPriceLocation
MouseAltaf2020-04-04 12:02:25.2475521000Nizamabad
LaptopPradeep2019-08-06 04:33:22.72152160000Hyderabad
Wireless_keyboardBhanu2016-02-27 04:20:27.2634202000Vijayawada
MobileVani2018-05-22 10:20:25.26556310000Cochin
HeadsetRam2022-02-20 11:39:37.5223215000Delhi
EarphonesRahim2021-11-29 09:19:23.4323562000Lucknow
HarddiskCharan2019-12-30 12:54:25.1223867000Bangalore

Example 3:

Let us create a table called player_desc which contains all the basic information of a player like player name, player time, player home city, etc.

CREATE TABLE player_desc(
Player_id INT AUTO_INCREMENT,  
Player_name VARCHAR(100) NOT NULL,
Player_team VARCHAR(20) NOT NULL,
Player_homecity Varchar(20) NOT NULL,
PRIMARY KEY(Player_id)
  );

 Let us insert data into this table by an insert into command

INSERT INTO player_desc VALUES
('Virat Kohli', 'India', ‘Delhi’),
('David Warner, 'Australia, 'Paddington’),
('SKY', 'India', ’Mumbai’),
('MS Dhoni', 'India’, ‘Ranchi’),
('JOS Butler', 'England', ‘Taunton’),
('Steve Smith', 'Australia', ‘Saint George’),
('Glenn Philipps ', 'New Zealand', ‘East London’),
('Glenn Maxwell', 'Australia', ‘Kew Australia’),
('Rishabh Pant', 'India', ‘Roorkee’),
(‘ABD’, ‘South Africa’, ‘Transvaal Province’),
(‘Eoin Morgan’, ‘England’, ‘Dublin’),
(‘Dwayne Bravo’, ‘West Indies’, Trinidad’),
(‘Ravindra Jadeja’, ‘India’. ‘Navagam-Khed’),
(‘Suresh Raina’, ‘India’, ’Muradnagar’);

We can check the data of table by using the following command:

SELECT * FROM player_desc;

The table will look like:

Output:

Player_idPlayer_namePlayer_teamPlayer_homecity
1Virat KohliIndiaDelhi
2David WarnerAustraliaPaddington
3SKYIndiaMumbai
4MS DhoniIndiaRanchi
5Jos butlerEnglandTaunton
6Steve SmithAustraliaSaint George
7Glenn PhilippsNew ZealandEast London
8Glenn MaxwellAustraliaKew Australia
9Rishabh PantIndiaRoorkee
10ABDSouth AfricaTransvaal Province
11Eoin MorganEnglandDublin
12Dwayne BravoWest IndiesTrinidad
13Ravindra JadejaIndiaNavagam-Khed
14Suresh RainaIndiaMuradnagar

Example 4:

Let us create a table named Subscription info which consists of information different types of subscriptions which are purchased by various customers.

create table Subscription_info(customer_name VARCHAR(200), Subscription_ info VARCHAR(200) purchasetime VARCHAR(200));

Now, insert some data in the subscription_info table.

insert into Subscription_info 
values('Priyanka', 'Gold', ‘03:13:20’),
 ('Abrar', 'Basic', ‘02: 23:39’),
 ('Karthik', 'Premium', ‘05:45:30’),
('Mahesh', 'Basic', ‘06:30:32’),
('Surya', 'Premium', ‘11:25:35’),
('Lokesh', 'Basic', ‘10:32:50’),
('Keerthi', 'Gold', ‘09:22:55’),
('Rakesh', 'Premium', ‘11:42:53’),
(‘Vamshi’, ‘Basic’, ‘12:30:00’),
(‘Rahul’, ‘Basic’, ‘10:55:00’);

We can check the data of table by using the following command:

SELECT * FROM Subscription_info;

Output:

customer_nameSubscription_infopurchasetime
PriyankaGold03:13:20
AbrarBasic02:23:39
KarthikPremium05:45:30
MaheshBasic06:30:32
SuryaPremium11:25:35
LokeshBasic10:32:50
KeerthiGold09:22:55
RakeshPremium11:42:53
VamshiBasic12:30:00
RahulBasic10:55:00

Example 5:

Consider the below table called employee and create attributes like emp_id, emp_name, and department.

CREATE TABLE employee( emp_id INT AUTO_INCREMENT,
                  emp_name VARCHAR (100),
                  department VARCHAR(200));

Now, insert some data of employees in the employee table.

INSERT INTO employee VALUES(‘Suresh’, ‘Executive’),
(‘Shreya Singh’, ‘Operations’),
(‘Kavitha Kulkarni ’, ‘Human resources),
(‘Raj Pawar’, ‘Marketing’),
(‘Jay Sharma’, ‘Research and development),
(‘Sravan Kumar’, ‘Operations’),
(‘Ranjith Kumar’, ‘Executive'),
(‘Harish’, ‘Research and development),
(‘Rajnish’, ‘Marketing’),
(‘Pritam Sharma’, ‘Executive’);

We can check the data of table by using the following command:

SELECT * FROM employee;

Output:

emp_idemp_namedepartment
1SureshExecutive
2Shreya SinghOperations
3Kavitha KulkarniHuman resources
4Raj PawarMarketing
5Jay SharmaResearch and development
6Sravan KumarOperations
7Ranjith KumarExecutive
8HarishResearch and development
9RajnishMarketing
10Pritam SharmaExecutive

This is all about inserting multiple rows in MYSQL. Hope you understood this topic.


Related Topics

Drop vs Truncate in SQL

In this article, we will learn and understand the Drop and Truncate commands and the difference between these two commands. What is Drop Command? Drop is a Data Definition Language command in...

6 minutes read.

SQL INSERT Statement

In this tutorial, we will help you to understand and learn how to insert records to the table in SQL with the help of examples. SQL INSERT query is used to...

5 minutes read.

Pattern Matching in SQL

The LIKE in the Structured Query Language is a Logical Operator. The SQL LIKE is used within the WHERE clause in the SQL. This Like Operator is used with the...

5 minutes read.

SQL Aliases

SQL Aliases: These are used to give a temporary name for a column or table. These are used to make tables or columns more readable. These are used to rename the table...

2 minutes read.

SQL SELECT AND Operator

This SQL tutorial explains and helps us understand how to use the AND Operator in the SELECT query with examples. The AND Operator is used to fetch the table’s records if...

2 minutes read.

space() function in SQL

 This function returns a string with a specified number of spaces. If we specify a number, it returns the strings having that specified number of spaces. SPACE Function is available...

2 minutes read.

Trigger in SQL

In this article, we will learn about the concept of trigger in SQL and its implementation with the help of an example. A Trigger in Structured Query Language is a set...

4 minutes read.

SQL Wildcards

SQL WILDCARD CHARACTERS: SQL wild card character is used to substitute zero or more characters of a string. These characters are used with the “LIKE” operator. Wild Card Characters in SQL: %_[]^- “%” : It is...

3 minutes read.

How to delete a row in SQL

Introduction To delete or remove the unused/unwanted rows from a table, DELETE command is used in SQL.DELETE command removes the entire record from a table.The DELETE statement can delete one or...

6 minutes read.

SQL Except

In SQL, we probably use the JOIN clause to receive the combined result from one or more than one table. But sometimes, we want a result that contains data from...

4 minutes read.

Types of SQL Commands

The Structured Query Language is used to deal with structured data. The data which are stored in the form of tables are structured data. These SQL commands store records or...

10 minutes read.

How to Create Temporary Table in SQL?

How to Create Temporary Table in SQL  Introduction to Temporary Tables Temporary table is a table which is used to store temporary data that can be used further in the same client...

3 minutes read.

SQL DROP Database

This tutorial will help us understand how to drop a database from the SQL Server with a few examples. The DROP command removes all the objects stored in the database and...

4 minutes read.

SQL Formatter

As a beginner, one does not focus much on Formatting the queries while writing their code. This leads to a great confusion while referring the code in future. For a...

5 minutes read.

How to remove duplicates in SQL

Introduction There are some specific rules that needs to be followed while creating the database objects. To improve the performance of a database, a primary key, clustered and non-clustered indexes, and...

9 minutes read.

Codd’s Rules in SQL

Codd’s Rules Dr. Edgar F. Codd, in 1985, laid down 13 fundamental rules after doing large-scale research on the Relational Model of databases. According to him, every database must follow these...

3 minutes read.

SQL INTERSECT

SQL intersect operator is used to combine two or more SELECT statements, but it only displays the data similar to the SELECT statement. The syntax for the INTERSECT operation: SELECT COLUMN_NAME1, COLUMN_NAME2,...

3 minutes read.

Introduction to SQL

SQL Introduction SQL is Standard Query Language. This language is used to communicate or interact with database. In other words, SQL is used to access and manage data or information...

2 minutes read.

How to Update Table in SQL?

How to Update Table in SQL Introduction UPDATE query is used to update a record in a table. UPDATE is a DML command, which operates on the data of the table and not...

4 minutes read.

DML Commands in SQL

DML is an abbreviation of Data Manipulation Language. Data Manipulation Language commands in Structured Query Language manipulate the data in the database. DML commands are used to retrieve records, add records,...

4 minutes read.