Google Answers Logo
View Question
 
Q: Moving records between databases (SQL Server 2000)... ASAP!! ( No Answer,   0 Comments )
Question  
Subject: Moving records between databases (SQL Server 2000)... ASAP!!
Category: Computers > Programming
Asked by: tangelo-ga
List Price: $15.00
Posted: 13 Mar 2006 11:51 PST
Expires: 13 Mar 2006 12:34 PST
Question ID: 706831
I am trying to move records from a table in one database to a table
with identical structure in another database for archiving purposes.
My tables are very large with lots of fields, so for a simplified
example, suppose I have a database called People which has a table
Personal_Info with the fields First_Name, Last_Name, Birth_Year
and another database called Old_People with a matching Personal_Info table.

I want to be able to move entries from the People table into the
Old_People table based on how old they are.  Is there any
straightforward way to do this?  I am sending the db queries from C#,
so I could query the People db to get the entries I want to move,
generate the inserts into the Old_People db, then do the deletes in
the People db, but I'm hoping for a better (cleaner / faster)
solution.
I read about using an IN statement to specify a different database,
but when I tried the statement below it gave me a syntax error near
IN.

SELECT * INTO Personal_Info IN Old_People FROM Personal_Info WHERE
Birth_Year < 1900


To clarify what I want to have happen, here is an example:

Starting State:
-------------------------------------------
DB People
   TABLE Personal_Info
      FIRST_NAME   LAST_NAME   BIRTH_YEAR
      John         Doe         1873
      Suzy         Q           1955
      Bobby        Smith       1984
      Alice        Black       1884

DB Old_People
   TABLE Personal_Info
      FIRST_NAME   LAST_NAME   BIRTH_YEAR
      Peter        Piper       1564
      Jane         Doe         1689

-------------------------------------------

Should become:
-------------------------------------------
DB People
   TABLE Personal_Info
      FIRST_NAME   LAST_NAME   BIRTH_YEAR
      Suzy         Q           1955
      Bobby        Smith       1984

DB Old_People
   TABLE Personal_Info
      FIRST_NAME   LAST_NAME   BIRTH_YEAR
      Peter        Piper       1564
      Jane         Doe         1689
      John         Doe         1873
      Alice        Black       1884

-------------------------------------------


I cannot make any major changes to the structure of the People
database or the tables within it, but I have complete control over the
Old_People db.

I'm looking for either:
-the query statement for moving records between two databases (not
using "IN" unless I'm using it incorrectly and you can get it to work
for me!)
OR
-if it can't be done with a query, then tell me! and provide
suggestions on the best way to make it happen through code.  For
example, can I use my resultset directly for an insert into another
db?  Or do I really have to generate and run all of those insert
statements?


I will give extra tip if you also provide a way to create the
Old_People db and Personal_Info table within on the fly if it doesn't
already exist.


Thank you in advance!
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy