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

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:-
select *into[new table] from [existing table]
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.
insert [first table] select *from[second table]
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.
insert into [first table](column2,column3,column1)select(column2,column3,column1)from [Second table]
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

For More:-

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

1 comment:

Powered by Blogger.