September 12, 2014 at 12:59 pm
Hi,
I have two tables
Table1 Table2
1 5
2 6
3 7
4 8
How to swap table2 values in Table1 & Table1 to Table2...?
September 12, 2014 at 2:18 pm
karunakar2351 (9/12/2014)
Hi,I have two tables
Table1 Table2
1 5
2 6
3 7
4 8
How to swap table2 values in Table1 & Table1 to Table2...?
It depends on what exactly you want to do, you can rename the tables or you can swap the values.
For renaming use sp_rename, Table1 to Table1_temp, Table_2 to Table1 and Table1_temp to Table2
For the swap, select * into #temp1 from Table1, Truncate Table1, insert into Table1 select * from Table2, Truncate Table2, insert into Table2 select * from #temp1, drop #temp1
😎
September 12, 2014 at 4:29 pm
This sounds an aweful lot like an interview question.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 13, 2014 at 5:51 am
Jeff Moden (9/12/2014)
This sounds an aweful lot like an interview question.
Yep, sure smells like one
😎
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply