How to copy data from one table to another table in SQL SERVER

By
1.    If we want to create new table containing same column and records  as specify within existing table then following SQL command will be  used:-
SYNTAX:-
select *into[new table] from [existing table]
Example:-
Here I have a student table (already build). we want to copy this table data to another new table(student4) by creating new table(student4)  at run time .


select *into student4 from student
See the student4 records.
select*from student4

  2. Copy the data in two existing table.
SYNTAX:
insert [first table] select *from[second table]
Example:-
Here i have two table (student, student1).we want to copy student table data to student1 table.
insert student1 select *from student
 see the student1 table data.
select*from student1


 3. Copy two table data when both table's Data type is different.
SYNTAX:-
insert into [first table](column2,column3,column1)select(column2,column3,column1)from [Second table]
Example:-
Here I have two table (emp4 and student).here both table Data type sequence is not same.
See  First table:-


See Second table:-


 SQL QUERY to copy the student table data to the emp4 table :-


insert into emp4(sid,sname,sage)select sid, sname,sage from student

SEE IT:
For More:-

I hope this helpful for you.
click below for download whole command.
      DOWNLOAD

1 comment:

Powered by Blogger.