mssqldump, a small utility to dump MS SQL Server data

In the past few months I found myself busier with moving data here and there, so much that scripts ending with load(transform(extract())) have become my bread and butter — sad life, some say!

Last night I wanted to import a bunch of data stored in SQL Server into a MySQL database, but didn’t want to get my hards dirty with a GUI or PowerShell because, well, PowerShell.

The result was mssqldump, a small utility – similar to mysqldump – to export data into TSV.

Usage

mssqldump does one thing — and hopefully well — run a query against the database and export the results as TSV to the stdout:

1
2
3
4
5
6
./mssqldump -q "SELECT Name, 1 as ID, RAND() as thing from sys.Databases"
master    1    0.4318099474883688
tempdb    1    0.4318099474883688
model     1    0.4318099474883688
msdb      1    0.4318099474883688
test      1    0.4318099474883688

You can also include headings (column names) with the -c option:

1
2
3
4
5
6
7
./mssqldump -q "SELECT Name, 1 as ID, RAND() as thing from sys.Databases"
Name      ID   thing
master    1    0.4318099474883688
tempdb    1    0.4318099474883688
model     1    0.4318099474883688
msdb      1    0.4318099474883688
test      1    0.4318099474883688

If you want to print mssqldump’s version information you can just specify v or version as the query parameter:

1
2
./mssqldump -qversion
1.0.0

If you want to use mssqldump simply download the latest release from github and start dumping data around!

A couple surprises

Building mssqldump was an experience on its own, as I discovered a couple useful things:

Adios!


In the mood for some more reading?

...or check the archives.