Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    23

    Unanswered: importing data from sql server to mysql

    Hi,
    I have a huge database that is in sql server, and now I'm converting to mysql. I have all the tables created in mysql now I want to import the data that is in sql server into the mysql tables. Is there an easy way to do this? If someone can help, please do so. And another thing, could someone give me a sample of an If else statement.
    This is what I have and I keep getting an error.

    set @var = 1;
    if not (@var = 0) then
    select * from table1
    else
    select * from table2
    end if;

    thanks

  2. #2
    Join Date
    Oct 2003
    Location
    Denver, Colorado
    Posts
    137

    Re: importing data from sql server to mysql

    I am assuming that the tables have the same definition. If they do, then you can use the following code to accomplish the task:

    Code:
    CREATE TEMPORARY TABLE omega 
    SELECT * FROM table1;
    
    ALTER TABLE omega ADD COLUMN tablename INT;
    
    UPDATE omega SET tablename = 1;
    
    INSERT INTO omega(<columnlist omitting tablenamet>) SELECT * FROM table2;
    
    UPDATE omega SET tablename = 2 WHERE tablename IS NULL;
    
    SET @tableid = IF(@var=0, 2, 1);
    
    SELECT * FROM omega WHERE tablename = @tableid;

  3. #3
    Join Date
    Dec 2003
    Posts
    23
    aus,
    You might have to guided me through this. Where do I run this peace of code?

  4. #4
    Join Date
    Oct 2003
    Location
    Denver, Colorado
    Posts
    137
    By "accomplish this task" I meant to replace the If-Then statement. Just use the code I wrote in place of an If-Then statement (changing the <> to the real column names).

    But to get the data from SQL Server into MySQL you probably need to use DTS. Follow the wizard through and your data should move just fine. If you need more help on DTS, the SQL Server forum is probably a better place to ask.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •