Copy data from one table to another existing table in sql server | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Copy data from one table to another existing table in sql server

Introduction: In this article today I will explain how we can copy data from one table to another existing table sql server
Description:  
Insert into Table2 Select * from Table1;
Syntax to copy only columns:
Insert into table2(Columns_Name, Columns_Name) select Columns_Name, Columns_Name from from table1;
Note: Here in the above query we select data from table 1 and insert it into table 2. Table 1 will be source and table2 will be target table

Example:

I have two tables:
Old_Student :
Create table Old_Student
(
Id int not null primary key,
Student_Name varchar(50),
Student_Address varchar(50),
Phone_No int
)
New_Student:
Create table New_Student
(
NId int not null primary key,
NStudent_Name varchar(50),
NStudent_Address varchar(50),
NPhone_No int
)
Here now I want to copy the record from New_Student table and insert into Old_Student.
Insert into dbo.Old_Student(Student_Name,Student_Address,Phone_No) select NStudent_Name,NStudent_Address,NPhone_No from dbo.New_Student;


Is this article helpful for you?
If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget