We have different ways to insert data in a table. The traditional approach is time consuming and boring because we have to repeat the same syntax again and again.
The following script helps to create the table.
- Create table Mas_Employee(
- Id int primary key identity(1,1),
- Name varchar(50),
- Salary int ,
- DeptId int
- )
Traditional Method
Method 1 : Insert statement with column list.
- insert into Mas_Employee ( Name, Salary, DeptId ) values('Jaipal',18200,1);
- insert into Mas_Employee ( Name, Salary, DeptId ) values ('Jayanth',14200,2);
- insert into Mas_Employee ( Name, Salary, DeptId ) values ('Sreeshanth',12999,2);
- insert into Mas_Employee ( Name, Salary, DeptId ) values ('Tejaswini',16800,1);
Method 2 : Without using column list (into is optional).
- insert Mas_Employee values ('Jaipal',18200,1);
- insert Mas_Employee values ('Jayanth',14200,2);
- insert Mas_Employee values ('Sreeshanth',12999,2);
- insert Mas_Employee values ('Tejaswini',16800,1);
Method 3 : You can also use graphical representation.
Go to Object Explorer, then Databases, your Database. After that, go to Tables and open Mas_Employee table by clicking on it. Select 'Edit Top 10000 Rows' and insert your data
Single insert statement to Insert multiple records in table.
- insert into Mas_Employee ( Name, Salary, DeptId ) values
- ('Jaipal',18200,1),
- ('Jayanth',14200,2),
- ('Sreeshanth',12999,2),
- ('Tejaswini',16800,1);
I hope you enjoyed it. Please provide your valuable suggestions and feedback if you found this article helpful.