0

I have a table name student with fields, name and roll in my-sql database. Also, I have a same table name student in MS-SQL database with the fields, name and roll.

When a value inserted into my MySQL database student table, I need to auto-insert the same value into the MS-SQL database student table.

2
  • First, as similar as MySQL and SQL Server are with respect to data types -- they're still different vendors. Which is why what you ask for is fairly unusual... If you were going the other way - SQL Server to MySQL, it'd be easy using a Linked Server instance. Commented May 10, 2011 at 3:29
  • that mean .it's not possible to migrate data from mysql to MS-SQL server??pls suggest.also what is linked server Commented May 10, 2011 at 3:38

2 Answers 2

1

Why are you using two separate databases to do the same thing? can't you just choose one? If you are just trying to export and import data you should be able to export as a csv from one database and import into the other, and then only use the database you need to.

If not i suppose you could write a class that wraps around two database objects and actually executes every query on both databases.
for example:

public class database
{

public DbConnection mySqlConnection;
public DbConnection sqlConnection;
/// <summary>
/// open two db connections
/// </summary>
   public database()
   {
      mySqlConnection =//string that will open the mysql

      mySqlconnection = //insert string will open the sql server database
   }

   public excecuteNonQuery(String SQL)
   {
     //cmd1 = mysql command
     //cmd2 = mssql command

     cmd1.excecute(SQL);
     cmd2.execute(SQL);

   }
}

And just create functions that handle preparing the commands and inserting the data, so that the operations are performed at the same time on both of the databases. I'm not aware of any method of replicating a mysql database to a mssql database.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your ans...If data migrating is not possible..then we have to go for that solution.Basically, it is the last solution..
1

You could have a cron that runs every so often to insert records it hasn't seen yet.

// Assuming the primary key is an id int auto_increment
startId = getLastIdFromPreviousRun();
lastId = 0;
offset = 0;
while(true) {
    mysqlrs = mysqlQuery(
        "SELECT * FROM users WHERE id > ? ORDER BY id LIMIT ?, 1000",
        startId,
        offset
    );
    if (!mysqlrs || mysqlrs.count() == 0)
        break;
    foreach(mysqlrs as mysqlrow) {
        mssqlInsert('users', mysqlrow);
        lastId = mysqlrow['id'];
    }
    offset += 1000;
}
if (lastId) {
    setLastIdForNextRun(lastId);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.