Solved

partition switch

Posted on 2011-03-17
2
197 Views
Last Modified: 2012-06-21
Can you perform partiton switch between two tables even though two tables are in different database ( same server)?
I have table A  in database A and table B in database B and  i would like to use parttiion SWITCH to move data from table A to Table B..  i am using sql server 2008 R2
0
Comment
Question by:jung1975
2 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35161163
no. see here:
http://msdn.microsoft.com/en-us/library/ms190273.aspx

reason:
Both the source table or partition, and the target table or partition, must reside in the same filegroup.

this restriction is logical, btw, as this statement will do nothing but change the points, it will NOT move actually any data.
0
 
LVL 28

Accepted Solution

by:
Ryan McCauley earned 500 total points
ID: 35163024
You can't move data between tables (let alone databases) using an ALTER TABLE statement like that. To move that data, you'd have to do an old-fashioned INSERT followed by a DELETE. Or, to do it in a single statement, you could try this:

DELETE DatabaseA.TableA
OUTPUT deleted.*
  INTO DatabaseB.TableB

Open in new window


This will delete the rows from TableA and put them in TableB in a single, atomic transaction. If any part of the insert/delete fails, it will roll the whole thing back and leave the rows where they started.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now