Skip to content
Related Articles
Open in App
Not now

Related Articles

Insert statement in MS SQL Server

Improve Article
Save Article
  • Last Updated : 05 Aug, 2020
Improve Article
Save Article

A database contains of many tables which has data stored in an order.  To add up the rows, the user needs to use insert statement. 

Syntax : 
 

insert into table_name(column_list)
values(values_list) 

For better understanding, an example is given below. 

Example – 
A table named student must have values inserted into it. It has to be done as follows: 

 

insert into student (varchar2 name(20), int rollnumber, varchar2 course(50));
values('Riya', 111, 'Computer Science'); 

Output – 
 

1 row(s) inserted 

To check whether the value is actually inserted, the query must be given as follows: 
 

select *
from student; 

Output – 

 

NameRollnumberCourse
Riya111Computer Science

insert multiple rows : 
A table can store upto 1000 rows in one insert statement.  If a user want to insert multiple rows at a time, the following syntax has to written. 

Syntax : 
 

insert into table_name(column_list)
values(value_list1)
values(values_list2)
.
.
.
.
values(values_listn) 

If a user wants to insert more than 1000 rows, multiple insert statements, bulk insert or derived table must be used. 

Example – 
Consider a table student. If a user has to enter the data of 6 students at a time, the query must be given as follows- 
 

insert into student(int rollnumber, varchar2(30) name, varchar2(20) course);
values(111, 'Riya', 'CSE');
values(112, 'Apoorva', 'ECE');
values(113, 'Mina', 'Mech');
values(114, 'Rita', 'Biotechnology);
values(115, 'Veena', 'Chemical');
values(116, 'Deepa', 'EEE'); 

Output – 
 

6 row(s) inserted 

To check whether the values are present in the table, the query must be given as follows: 
 

select *
from student; 

Output – 

 

Roll numberNameCourse
111RiyaCSE
112ApoorvaECE
113MinaMech
114RitaBiotechnology
115VeenaChemical
116DeepaEEE

The insert multiple rows statement was only available in the year 2008 and later on. 
 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!