Search code examples
mysqlsqldatabasedata-transfer

Transfer Data Between Two MySQL Databases Without Unnecessary Schema Changes


I have two databases with a large number of tables in each.

database A is a empty and database B has around one thousand records.

database A has some extra tables that database B doesn't, for instance database B has a students table and a parents table, while database A has those and a course table.

The two databases have the same table names, but database A has more columns in each table than database B. For example, the students table of database B includes columns for name, age, and address, but the corresponding table in database A has those columns in addition to country, sex.

When I try to transfer data using dreamsql, the extra columns in database A are deleted. How can I transfer my data between two tables without incurring changes to the database schemas?


Solution

  • Well It's just like manual Insertion... No need to get confused

         var con = new DatabaseAEntities;
            var names = con.names;
    
            SqlCeConnection cn = new SqlCeConnection(@"Data Source=G:\DataBaseB.sdf");
    
            foreach(var name in names)
            {
            string x = name;
            cn.Open();
                SqlCeCommand cm = new SqlCeCommand("INSERT INTO names(Name) VALUES(@Name)", cn);
                cm.Parameters.AddWithValue("@Name", x);
                cm.ExecuteNonQuery();
                MessageBox.Show("Added Successfully");
                cn.Close();
            }