Solved

partition switch

Posted on 2011-03-17
2
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

726 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