Alternative queries equivalent to Oracle's Analyze Table Query - mysql

Are there queries in other databases equivalent to Oracle's very useful ANALYZE TABLE.. ? I am looking for alternatives for the following Database vendors:
MySQL
MS SQL Server [2000, 2005, 2008]
Thanks in advance

MySQL has ANALYZE TABLE as well, see here:
http://dev.mysql.com/doc/refman/5.5/en/analyze-table.html

Have a look at SQLServer-DBA.com at this page for a statistics overview and another page on how to gather statistics in MS SQL Server. I don't know of other vendor implementations.
Further research shows that SQL Server has the CREATE STATISTICS command, which looks to be the equivalent.

Related

Querying data by joining two tables in two databases (different database types) on different servers

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

How can i export MS SQL into MySql table?

How can i export large tables from MS SQL into MySql table. Please note that the tables a large and.
I tried the mysql migration toolkit that is in MySql Workbench but i could not establish connectons to the SQL server
Please advise me on the best way to do this?
Thanks :)
One method of doing it (if it really is a lot of data and a lot of tables): creating a linked server in SQL Server and using it to push data into MySQL.
This article gives step-by-step instructions to create the linked server.
ANd then just run queries against your tables like so:
INSERT INTO OPENQUERY (<LINKED SERVER>, 'SELECT * FROM MySQL_Table')
SELECT * FROM dbo.SQL_Table

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.

MySQL trigger to update SQL Server table

Is it possible to update a table in SQL Server using a trigger in MySQL. The scenario is like this.
When a table is updated in MySQL, a corresponding update is to be done in SQL Server for the purpose of syncing certain fields. I understand that the reverse is possible using a linked server in SQL Server.
You can write a UDF function that would update data in the SQL Server. Then call this UDF from the trigger.
Here's some information which may be of help regarding linking SQL Server and MySQL
http://forums.mysql.com/read.php?60,123221,123221
I'm afraid I've no personal experience in the matter as I thankfully have MySQL servers across the board, however had a scan through the links in the above and at least one of them should be able to assist.

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.