Search code examples
c#sql-serversql-server-ce

Can I insert SDF data into an MDF?


I have two databases:

  1. DatabaseA.mdf
  2. DatabaseB.sdf

Database B is a compact version of Database A. I would like to merge them together so I can eventually get rid of DatabaseB.

They have the same tables and same structure but how can I achieve this?

I want to write a C# program which will simply run something similar to the following script:

INSERT INTO [DatabaseA].[table] (column1, column2...) 
VALUES 
    (
    SELECT column1,column2... 
    FROM [DatabaseB].[table] 
    WHERE [UID] NOTIN [DatabaseA].[table]
    )

I am aware, this isn't the final query.

Many thanks,

Sam


Solution

  • There are tones of ways, but I would use DataSet in this case

    1. Read from DB B into DataSet
    2. Read from DB A into DataSet
    3. Merge this two DataSets using DataSet.Merge
    4. Store result DataSet into DB A