Skip to content
Related Articles

Related Articles

Improve Article

SQL Query to Insert Multiple Rows

  • Last Updated : 13 Sep, 2021
Geek Week

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:

Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course  by GeeksforGeeks.

My Personal Notes arrow_drop_up
Recommended Articles
Page :