move table1 contents to table2 from different databases

davidvilson
davidvilson used Ask the Experts™
on
Dear experts,

I got a request in my office today ..

I need to move contents from table1 (from database1) to table2(database2)..

Could any one please tell me the sql/plsql/cursor code that will do this job of moving records from one table to other from different databases..
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AneeshDatabase Consultant
Top Expert 2009

Commented:
its been answerd with ur previous post

yes, you need to provide the qualified name for that  (databasename.dbo.tableName )

INSERT INTO  database1.dbo.Table2
SELECT * FROM  database2.dbo.Table1
IF @@ROWCOUNT > 0
  TRUNCATE TABLE Table1

Author

Commented:
But why this if@rowcount > 0, truncate table table1 ????

Author

Commented:
Also, since im doing this job every day as schedule, table1 records have to be appended to table2.. It should not simply add or over write in table2..
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Records should be appended to the existing table2.  does the above query appends?
Database Consultant
Top Expert 2009
Commented:
>Also, since im doing this job every day as schedule, table1 records have to be appended to table2.. It should not simply add or over write in table2..

Thats what an Insert statement do,

UPDATE statement is used to overwrite the contents with a new value

Author

Commented:
Sry, what an idiot Iam

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial