views:

53

answers:

2

Hello,

Say i have a table named tbl1 in mysql :-

bookid int
name varchar(20)
price int
categoryid int

And then i have a 2nd table, tbl2 in Oracle :-

pubid int
name varchar(20)
addr varchar(50)

I want to combine these two into MS Sql Server 2008 named tbl3 whose structure should be :-

bookid int
name varchar(20)
price int
pubid int
name varchar(20)

Note that i know the tables are not meaningful but i just need the concept whether this thing is possible or not. And if yes then how? Which queries should i write? I don't want to use Sql Server Integration Services.

Thanks in advance :)

A: 

Do they have a common column that you can run a join on. For example does the categoryid in the first table match the pubid in the second. Does name from table1 match with name in table2. If so is name the key, no other book with have the same name with each other. If so run a join on the tables using name as the common key.

If there is no common key then you can do select * from table1, table2, ..., tablen. This would work into a really large table. If you join two tables with 12 rows each then your resulting table would have 12*12 = 144 rows in total.

Kyra
Hi Kyra, there is no common column. What to do in this case?
Ankit Rathod
@Nitesh Panchal I updated the answer. Hopefully this helps
Kyra
+1  A: 

You will need something that can communicate with each of the databases. If SQL Server is the desination, and you don't want to use DTS/SSIS, then you could use Linked Servers. The only question is how the data from Oracle relates to the data from MySQL since there is no matching column. Regardless, persuming you had a Linked Server called "ORACLESERVER" and another called "MYSQLSEVER", you could do something like (assuming that name was the linking column):

Insert SqlServerDbName.SchemaName.TableName(....)
Select ...
From ORACLESERVER.DbName.SchemaName.tbl1 As T1
    Join MYSQLSERVER.DbName.SchemaName.tbl2 As T2
        On T2.name = T1.name

Another solution would be to use OPENROWSET to achieve a similar result.

Thomas
Hi Thomas, thanks for replying. But what if there is no join condition? I just want the records to appear side by side. For eg. row 1 of table3 should contain row 1 of table1 and table2. Similarly row 2 of table3 should contain row 2 of table1 and table2.
Ankit Rathod
@Nitesh Panchal - Without a common column, how would you determine which for a given of say Oracle data, which row(s) from the MySQL should go with it? If you want them side by side, you *must* have something to join them.
Thomas