Solved

partition switch

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

747 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

12 Experts available now in Live!

Get 1:1 Help Now