c# - How to merger/combine data from two sql databases that have a same structure? -


i writting program in c#, use sql server database.

my program include blank database (sample database) allow users can create new database.

for example:

  • user 1 use program create new database (db1) on computer, import/enter data db1
  • user 2 use program create new database (db2) on computer, import/enter data db2

now, have both 2 database (db1, db2). know how merge/combine 2 databases have unique database contain users' data ?

can me ?

please see demo screenshot diagram

if use of procedures applicable application might use merge statement combine data. learn more merging follow http://msdn.microsoft.com/en-us/library/bb510625.aspx topic

added output usage sample, shows how inserted row's pk insert in other related table.

create table #teachers(     [id] [int] identity(1,1) not null,     [name] [nvarchar](15) not null ) create table #pupils(     [id] [int] identity(1,1) not null,     [name] [nvarchar](15) not null ) create table #createdteachers ([id] [int]) create table #createdpupils ([id] [int])  insert #teachers output inserted.id #createdteachers values ('teacher#2')  insert #teachers output inserted.id #createdteachers values ('teacher#1')  insert #pupils output inserted.id #createdpupils values ('pupil#2') insert #pupils output inserted.id #createdpupils values ('pupil#1')  select t.id new_teacher_id,p.id new_pupil_id #createdteachers t , #createdpupils p 

i did not prepare sample, describes diagram necessary concepts shown. might use "select t.id new_teacher_id,p.id new_pupil_id #createdteachers t , #createdpupils p" insert teacherid, pupilid etc teacher_pupil table


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -