sql - Can I do a INSERT using select from another DB with the same table name -
i have person
table (sqlserver 2008r2) , using .vbs , .bat files sync data table called person
in database a
database b
.
note - db names different table names same. because peson
table has 137 fields looking way write both insert
, update
statement. how can thsi without listing 137 fields?
- at moment connect
database a
, populate recordset called rspeople
table records. - then loop through rs , query
people
table indatabase b
- if found update people table in
database b
people
table recorddatabase a
- if not found insert people record
database a
people
table ondatabase b
now nice , easy since has 137 fields not want write massive update , insert statements. have option such as:
the table structures identical between people
on database a
, people
on database b
recordset obtained in step 1 above using 1 one db connection , query in step 2 using separate db connection different db instance on different server.
help.
you can using qualified name.
insert database1.dbo.person (columns) select (columns) database2.dbo.person
also there others way pump data database can take on mssms got tool kind of thing. select 1 database , right button mouse open import/export wizard. can take on replication, bulk copy, service broker, etc...
Comments
Post a Comment