Mysqldump equivalent for Microsoft SQL Server
If you end up working in a wide variety of systems, you inevitably end up on system X, wishing that you had a specific tool or feature from system Y.
Today this happened to me, in that I wished I had something like mysqldump, but for MS SQL Server. The pointy-clicky stuff is fine in certain circumstances, but fails spectacularly in others.
This is a scenario where I didn’t own both boxes, and only have limited access to the source machine. So detach/attach and many other options are out of the picture. Copy database fails in a variety of ways in this situation, and the Export Data function also fails, as it’s not smart enough to try to insert table records in the right order to satisfy foreign key constraints.
And to top it off, I’d really like to have a nice snapshot of schema and data (this is a very small db) to push into SVN.
Unfortunately, the built in tools for MS SQL failed quite spectacularly here. This is a particularly frustrating limitation, as what should have been a 10-minute process to recreate the database on a new box turns into a sticky mess.
Fortunately, there is a solution, and it works quite well. To top things off, it’s open source (MS-PL) and created by Microsoft.
So now we can do wonderful things like this from the command line:
SqlPubWiz.exe script -d DBNAME -S SERVERNAME c:\db-schema.sql -schemaonly
SqlPubWiz.exe script -d DBNAME -S SERVERNAME c:\db-data.sql -dataonly
For the data extract, it actually uses an intelligent ordering, and produces SQL that generally ‘just works’, even with complex foreign key constraints.
There are other options as well if you want to control it to a greater degree.
This is close enough to mysqldump that it makes me quite happy, and even has a simpler syntax (though fewer options). Also note that this isn’t really ideal for very large databases. SSIS, bcp and other tools are a better choice in that scenario.
Do you have tools you like better? Let me know in the comments.
D’Mention Systems, LLC
Follow my other blog at:
Follow my business partner Mike’s blog at:
Are you looking for database or software experts to help you with your software project? Or need to integrate multiple systems or databases?