Introduction
This piece of code aims to export or convert MSSQL database to MySQL database.
It can be achieved with third party apps.
I'm not very proud of my code, it can be improved but it worked for me.
Background
There are 4 files:
- Batch to execute SQLCMD
- Table schema export
- Data export
- FK Export
This script uses information schema to get table/columns information.
It can be customized as you want.
Using the Code
Just update information in .bat file:
rem variables de connexion SQL
set host= your_host (local) or IP,PORT
set schema= your_schema
set user= your_user
set pass= your_password
Then execute (cmd or click).
3 files are created:
- tables.sql which contains table definitions
- data.sql which contains data
- fk.sql for fk
You will have to do a regex replace (with Notepad++):
- on table.sql: replace ",\r\n\r\n)" by "\r\n\r\n)"
- on data.sql: replace ",\r\n\r\n/" by ";\r\n\r\n/"
Points of Interest
My code is a little ugly, but the most interesting thing was to investigate into INFORMATIONS_SCHEMA
on MSSQL, and the way to produce another SQL script for MySQL.