Insert statement in MS SQL Server
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 –
Name Rollnumber Course Riya 111 Computer 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 number Name Course 111 Riya CSE 112 Apoorva ECE 113 Mina Mech 114 Rita Biotechnology 115 Veena Chemical 116 Deepa EEE
The insert multiple rows statement was only available in the year 2008 and later on.
Attention reader! Don’t stop learning now. Learn SQL for interviews using SQL Course by GeeksforGeeks.



