If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > importing data from sql server to mysql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-27-04, 11:43
xayavon xayavon is offline
Registered User
 
Join Date: Dec 2003
Posts: 23
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
Reply With Quote
  #2 (permalink)  
Old 01-27-04, 18:06
aus aus is offline
Registered User
 
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;
Reply With Quote
  #3 (permalink)  
Old 01-28-04, 13:22
xayavon xayavon is offline
Registered User
 
Join Date: Dec 2003
Posts: 23
aus,
You might have to guided me through this. Where do I run this peace of code?
Reply With Quote
  #4 (permalink)  
Old 01-28-04, 15:33
aus aus is offline
Registered User
 
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On