Solved

partition switch

Posted on 2011-03-17
2
199 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the 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 set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

777 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