Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

partition switch

Posted on 2011-03-17
2
Medium Priority
?
213 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

618 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