How to export MySQL database to MSSQL using phpMyAdmin

Using phpMyAdmin to export data has always been very useful to me, however I found when trying to run the SQL scripts it generates for Microsoft SQL server I found that there is a variety of incompatibilities. This is further compounded by the Microsoft SQL Management Studio that is a much improvement over the previous Enterprise Manager however it seems to fair badly when trying to do bulk inserts. I ran into many out of memory issues when trying to execute large SQL scripts over 25 megabytes. I also tried using the sqlcmd to try to have it directly process the files but it also ran into memory issues. I choose to use SQL scripts rather because this makes it easy to get back to the original database if needed.

phpMyAdmin Export Config
Exporting from phpMyAdmin
Select your database and then go to the Export tab. You will need to change the following options to have it export SQL file that is mostly compatible with MSSQL.

  • Change the export type to SQL
  • Under Options – Uncheck Comments, Change the SQL compatibility mode to MSSQL
  • Under Structure – Uncheck Add IF NOT EXISTS, ADD AUTO_INCREMENT value, Enclose table and field names with backquotes
  • Under Data – Uncheck Extended inserts

These options will ensure that the INSERT lines will be valid when importing.

Data Structure / Table Definitions
phpMyAdmin does not intemperate data definitions to be compatible. So you have to options here, use Microsoft Management Studio to create your tables or modify the SQL script to be compatible. Here are is an example of a definition that I fixed and what I did.

phpMyAdmin export Microsoft SQL Compatible
CREATE TABLE transactions (
id int(11) NOT NULL,
medmgrid float NOT NULL,
medmgridpri int(11) NOT NULL,
medmgridsub int(11) NOT NULL,
“date” date NOT NULL,
department int(11) DEFAULT NULL,
“type” text NOT NULL,
detail text,
doctor int(11) DEFAULT NULL,
“procedure” text,
description text,
reference_date date DEFAULT NULL,
diagnosis text,
unit float DEFAULT NULL,
amount float DEFAULT NULL,
total float NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE transactions (
id int IDENTITY(1,1)PRIMARY KEY,
medmgrid float NOT NULL,
medmgridpri int NOT NULL,
medmgridsub int NOT NULL,
“date” datetime NOT NULL,
department int DEFAULT NULL,
“type” text NOT NULL,
detail text,
doctor int DEFAULT NULL,
“procedure” text,
description text,
reference_date datetime DEFAULT NULL,
diagnosis text,
unit float DEFAULT NULL,
amount float DEFAULT NULL,
total float NOT NULL
);
  • ID Field is AUTO_INCREMENT in MySQL, for MSSQL use “IDENTITY(1,1)PRIMARY KEY”
  • INT does not allow specificaton of lenght, remove these entries “(11)” after each INT
  • DATE is not a valid datatype for MSSQL, replace with DATETIME
  • Any Data Field name that is also a Keyword for MSSQL needs to be Double Quoted
  • Remove ANY comments from the phpMyAdmin export, even if you didn’t check this there still maybe some in there. Be sure to check the end of the file for them.

For other datatype issues you may need to consult – http://webcoder.info/reference/MSSQLDataTypes.html and check to see if it is even a valid data type. Most datatype errors are easily resolved by Googling the error that is returned.

Data Insertion
If you have used phpMyAdmin export specifications from earlier in this article your data should mostly script in just fine. However, you may need to encase any of your Data Field names with double quote if the word is also a keyword. For example I have used the word Procedure which requires double quote or MSSQL thinks you are calling a stored procedure. To do this I would suggest a program called TextPad that not only does really fast replacements and can do it across multiple files but also is able to handle a few hundred megabyte text file with ease.

If you are using an AUTO_INCREMENT field you will need to add “SET IDENTITY_INSERT field_name ON;” line in before inserting any entry that tries to set that field to a specific value. This happens when your AUTO_INCREMENT ID field has already been created from MySQL. If you don’t do this you will receive an error of “Cannot insert explicit value for identity column in table ‘field_name’ when IDENTITY_INSERT is set to OFF.”

When doing bulk inserts you will be required to keep your single SQL file < 25 megabytes. Microsoft SQL Management Studio will prompt you with "The operation could not be complete. Not enough storage is available to complete this operation" or "System.OutOfMemoryException". To divide up these files I used a free program appropriately called TextWedge which was able to handle up to 100MB SQL files and easily divided them up. You may have to open SQL Studio, execute one 25MB SQL script then close and repeat depending on how much data you have to move.

Read More

Subsonic Internet Streaming Software Review

Recently I found myself at work without my Microsoft Zune mp3 player and wondered, is there a way for me to listen to all of my music from my home server? I did a few Google searches and found this great open-source project called Subsonic. Subsonic allows you to stream your mp3s across the internet to a browser or a phone or most other internet connected devices. You don’t necessarily have to have a home server to make the product work but it does need local access to the mp3s.

Interface
The interface is very simple for anyone to use. It lists all the bands on the right side and you can select though to view the different songs and albums you have in the main window. Then all you have to do is build a playlist and hit play. It will also show any album art for any of the albums you have (I’m not real big on album art as you can tell). It has a few different methods to play music but by far the most important for my use is the flash player that streams the mp3 directly to your browser. This is how I listen to my music everyday.

Subsonic Home Screen
Subsonic Song Selection

Features
Subsonic has tons of built-in features that makes it both flexible yet not complicated to get running. It has a lot of options that allow you to customize how the application transcodes on the fly files that aren’t mp3s so they can be played via the flash player. You can also limit the bandwidth to a player which can help if you are trying to support multiple users, have limited bandwidth from the server location or sending music to a mobile device (cell phone). It has an integrated WAP site so you can browse and build playlists with any phone with a browser. It also supports downloading of podcasts so you can listen to those as well, however I have yet to try this feature. The application also supports scrobbing to Last.fm so you can share with your friends what you listen to via Subsonic. The application also supports library searching so you can find whatever song you need for the moment without having to remember or browse to that artist.
For a full list of features please visit: http://www.subsonic.org/pages/features.jsp

Subsonic Search

Subsonic Status

Why I Use This App
This app was impressively easy to setup, and reliably streams all the music from my house to where ever I might be on the go. The interface is intuitive and supports search and Last.fm integration. On top of all of that it is free and open source, which I just love.

More Information
Website: http://www.subsonic.org/
Download: http://www.subsonic.org/pages/download.jsp
Installation: http://www.subsonic.org/pages/installation.jsp

Read More

Digsby Encounters The Dark Side Again

A while back I blogged about how Digsby had gone to the dark side, well with their most recent update they take another step in that direction. Today they introduced a new “feature” that allows: “Trending News: We’ve partnered with the folks at OneRiot to bring the latest trending news stories to your social feeds.”, in other words we put random spam in your feed.

Yes, this can be disabled by going Preferences > General & Profile and unchecking “Show trending news articles in social network feeds”, but that’s not really the point. Digsby continues to introduce features to increase their bottom line by auto-opting in all of their users without notifying them of the changes. How did they not learn their lesson from Facebook’s Beacon fiasco or even their own policy of automatically opting in users for their own for-profit research? I ask of you again Digsby if you are going to change the way your product work you need to explain it to the user and let them opt in or out. You’ve done this when you added features like achievements but you fail to do so when it comes to your bottom line. I ask you again please come back from the dark side.

Read More