Introduction: In this article today I will
explain how we can copy data from one table to another existing table sql
server
Description:
In the previous article I have explained Get multiple selected values from Listbox in asp.net, Explain cookies in asp.net OR Explain cookies with example in asp.net and Move items from one listbox to another listbox and vice versa in asp.net.
Syntax to copy all columns from one table to another existing table:
Syntax to copy all columns from one table to another existing table:
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.
No comments:
Post a Comment