Different ways of inserting records into tables using SQL query


In this article I am going to explain how to insert records into table using multiple methods in MS SQL

In this article I'm going to explain how to insert records into table using multiple methods.


To Create table :-


Create Table StudentMark(StudentID Int,StudentName VArchar(max),Mark int)



Method 1:
Insert one row at a time


insert into StudentMark values(1000,'Renganathan',500)
insert into StudentMark values(1001,'Ravi',600)
insert into StudentMark values(1002,'kumar',700)

Method 2:
Insert bulk rows into table retuned by the query

insert into StudentMark select * from StudentMark

Select table and insert table schema should match.

Method 3:
Insert query result into new table

select * into StudentMarkCopy from StudentMark

Inserting table in this query should not exist in database before executing this query.

Method 4:
Insert rows into table returned by stored procedure

insert into StudentMarkCopy exec spGetEmpDetails

Number of columns returned by stored procedure shoud match with the inserting table(StudentMark).


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: