[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] SQL insert from another database



I've got an employee that is starting in SQL but does not know perl.  He
wants to copy rows from one database to another.  I would do this in SQL
or even SQL + Perl but I want to figure out how we could do this in just
SQL.

Here is a sample table.

users
  user_id  int,Primary,auto increment
  name


In scenerio one we want to delete all users in A and copy B to A.

delete from A.users;
insert into A.users select * B.users;

That works very well especially when there is no data in A.users.  

Here is the scnerio I want to do in SQL.

A.users:
 1, Joe
 2, Susan

B.users
 1, Scott
 2, Jack

I want to copy B.users.* into A.users.  But they users has a primary
key.  1,Scott would not be allowed to be copied?

insert into A.users (name) select B.users.name

Does that seem like it is the right way?

Chris