Querying data by joining two tables in two databases (different database types) on different servers - sql-server-2008

I have a MS SQL (SQL Server 2008) database with some data in it and a postgresql (9) database with other data. I need to do some queries to find related data. I know how to link two MS SQL databases together but not sure how to even start with the mixed database types.
The new company I work for has postgresql, I have not worked with it before. The guy I replaced was really the only one here who knew much about it. So no internal resources.
I'm not ready to build a solution in code at this point (.NET), just hoping to have a tool to do some queries.
Postgresql has table
Company
Company_id, Company_name, ....
MS SQL had table
Companies
company_name, postgresql_company_id, company_id, ....

If you ever need to run queries from Postgres that pulls data from SQL-Server, you can use foreign data wrappers. The ODBC driver should work fine:
http://wiki.postgresql.org/wiki/Foreign_data_wrappers
I'm not familiar enough with SQL-Server to give an authoritative answer on how to do it the other way around, but since Postgres speaks ODBC, I'm guessing it's close enough to how you make a SQL-Server talk with another one.
Related thread: SQL Server 2012: Add a linked server to PostgreSQL

Related

Pulling Data from MySql and dropping it into SQL

I was wondering if anybody had any advice or references that explain how to pull data from MySQL and drop it into SQLSever! Any input would be greatly appreciated!! Thanks!
You can add MySQL as a "linked server"
http://forums.mysql.com/read.php?60,123221,123221
Once you did that you can reference the MySQL tables, views, etc with their fully qualified name in regular SQL Server queries
I could not tell if you wanted to access a MySQL database because you were migrating to SQL server, or if you wanted to access a MySQL database on an ongoing basis. I am answering as if you want to migrate, because you already have an excellent answer on accessing MySQL from SQL Server.
If you want to migrate, mysqldump is one way to go. Its format is easily parsed.
You can also write the results of any MySQL table -- and SQL Server for that matter -- to .csv format. .csv format is nearly a universal transfer format for data.

Combine several mssql database to one mysql with php

We are handling a data aggregation project by having several microsoft sql server databases combining to one mysql database. all mssql database have the same schema.
The requirements are :
each mssql database can be imported to mysql independently
before being able to import each record to mysql we need to validates each records with a specific createrias via php.
each imported mssql database can be rollbacked. It means even it already imported to mysql, all the mssql database can be removed from the mysql.
we would still like to know where does each record imported to the mysql come from what mssql database.
All import process will be done with PHP .
we have difficulty in many aspects. we don't know what is the best approach to solve our problem.
your help will be highly appreciated.
ps: each mssql database has around 60 tables and each table can have a few hundred thousands .
Don't use PHP as a database administration utility. Any time you build a quick PHP script to transfer records directly from one database to another, you're going to cause yourself a world of hurt when that script becomes required for production operation.
You have a number of problems that you need solved:
You have multiple MSSQL databases with similar if not identical tables.
You have a single MySQL database that you want to merge the data into.
The imported data must be altered in a specific way before being merged.
You want to prevent all duplicate records in your import.
You want to know what database each record originally came from.
The solution?
Analyze the source MSSQL databases and create a merge strategy for them.
Create a database structure on the MySQL database that fits the merge strategy in #1, including all the new key constraints (like unique and foreign keys) required for the consolidation.
At this point you have two options left:
Dump the data from each of the source databases into raw data using your RDBMS administration utility of choice. Alter that data to fit your merge strategy and constraints. Document this, and then merge all of the data into your new database structure.
Use a tool like opendbcopy to map columns from one database to another and run a mass import.
Hope this helps.

MySQL to SQL Server migration

I have a mysql database full of data which I need to keep but migrate to SQL Server 2008.
I know end to end where the data should go, table to table but I have no idea how to go about moving the data. I've looked around the web but it seems there are 'solutions' which you have to download and run. I'd rather if possible do something myself in terms of writing scripts or code.
Can anyone recommend the best way to do this please?
You have several options here:
On the sql server side, you can set up a connection to your old mysql db using something called a linked server. This will allow you to write sql code for sql server that returns data from the mysql tables. You can use this to build INSERT or SELECT INTO statements.
You can write queries for mysql to export your data as csv, and then use the BULK INSERT features of sql server to efficiently import the csv data.
You can use Sql Server integration services to set move the data over from mysql.
Regardless of which you choose, non-data artifacts like indexes, foreign keys, triggers, stored procedures, and security will have to be moved manually.
Have you tried tool from MSFT called SQL Server Migration Assistance for MySQL ???
https://www.microsoft.com/download/en/details.aspx?id=1495
Try this tutorial it is very easy to perform migration to SQL Server from Mysql and is straightforward as mentioned
http://www.codeproject.com/Articles/29106/Migrate-MySQL-to-Microsoft-SQL-Server
Thanks
You can use the Import/Export Wizard that comes with SQL Server Standard Edition.
Select your 'data source' from MySQL using the ODBC data source. Note: You will need to first install the from ODBC driver for MySQL (ODBC Connector). Then, select your SQL Server destination. Select all tables, and fire it up. You will need to add your primary and foreign keys, and indexes manually.
A bit more automated means would be by using the SQL Server Migration Assistant for MySQL, also free. It has the benefit of recreating the relationships and indexes automatically for you. Probably your best bet.
I did it once, some time ago. First you could couple your mssql server to the mysql server using the odbc mysql connector
http://dev.mysql.com/downloads/connector/
After the connection is made you can write you database procedure as you would if it were two mssql db's. Probably easiest to write some sql batch scripts including a cursor where you run through every every row of a table an decide on a field basis where you will need the field in the future.
example of a cursor: http://www.mssqltips.com/tip.asp?tip=1599
If you decide to go with the cursor, you can play with the parameter to increase performance. I especially remember the FORWARD_ONLY parameter giving a big boost.

Select * from Database 1 and insert into database 2

I have 2 Database in my VB.net application. I am using 1st database for daily operations. I would like to send one of the table records to online database. How Can I do that? First database is MSSQL Online database is MYSQL. I have created connections already using MYSQL .net connector.
Any Help will be appreciated.
Regards
Have a look at using a Linked Server instance on SQL Server to write the data to MySQL using the four name notation.
SQL SERVER – Explanation and Example Four Part Name
SQL Server Four-part naming
Ok here is a rough set of steps you need to follow
Query the MSSQL database and retrieve the data you want. Storing it in a DataTable may be the best option starting off.
Loop through the DataTable rows and build an INSERT statement that will be run against the MYSQL database.
Execute the command against the MYSQL db.
This is the basics of what you need to do to get a simple working system. Also take a look at Transactions as a way to manage the rollback of data when something goes wrong.
I'm assuming this is a research project If you are planning on using this code in a production system then i would look into a different alternative such as uploading data files to a service attached to the MYSQL database. This would allow you to batch and retry an import when something goes wrong.

What's the difference between Oracle and Mysql when interpreting "Create Database "?

I used to use mysql, and in mysql database hold tables, but these concepts doesn't apply to oracle, so I don't quite understand the differences.
Update: The problem I am facing is, I need to do migration from Mysql to Oracle.
I have two switching databases called A and B, in Mysql all the tables are in their corresponding databases.
In mysql database is a logical concept, it use database to hold tables, in oracle database is physical concept, I don't know how to design this in oracle.
Do I need to use "CREATE DATABASE" to create two databases in oracle to achieve the same effect?
To answer your question you want to create a schema (CREATE USER) not an instance/database (CREATE DATABASE).
The Oracle definition of a database is the files on disk. These can be shared between instances (Real Application Clusters) or only used by a single instance (on the same server for example, the most common).
Background: The concept of "database" is different between database vendors. As an Oracle DBA I'm careful when talking to someone who is from an MySQL, DB2, SQL Server background, what they call a "database" in Oracle is a user/schema (difference between user and schema being a schema contains tables and a user is only a login). Whenever someone, developer especially, uses the word "database" question in what context.
Oracle's SQL Developer documentation has a chapter comparing MySQL with Oracle. Find it here. The reason it is here is because SQL Dev includes the Migration Workbench which supports migrating MySQL to Oracle. You might want to consider using the tool in your endeavours. It is free.
Anyway, the documentation has this answer to your specific question:
"When migrating MySQL databases to
Oracle, SQL Developer maps each MySQL
database to a tablespace in Oracle.
Database objects, such as tables,
indexes and views are stored in the
respective tablespaces and are
referenced from the Oracle schema for
the user that owns them."