SQL: Scripting SQL Server objects and data from the command line

SQL: Scripting SQL Server objects and data from the command line

The other day I posted a shortcut article about how to use SQL Server Management Studio (SSMS) to generate INSERT statements for data.

In one of the comments, a reader asked if there was a way to do that from the command line.

The answer is yes, sort of. Apart from a variety of 3rd party tools, a few years back, Microsoft released tools to do just that.

The easiest tool was probably mssql-scripter and you’ll find an intro to it here:

https://blogs.technet.microsoft.com/dataplatforminsider/2017/05/17/try-new-sql-server-command-line-tools-to-generate-t-sql-scripts-and-monitor-dynamic-management-views/

They described it as “the multiplatform command line equivalent of the widely used Generate Scripts Wizard experience in SSMS”.

Importantly, note the fact that it’s multiplatform. It’s built in python and works on Linux, macOS, and Windows and can create both DDL and DML scripts that target SQL Server, and that also includes Azure SQL Database and Azure SQL Managed Instance.

You choose where the output goes. Normally you’ll send it to .sql files but like any other Unix style utility, you can pipe its stdout to other commands.

The source code is up at github here:

https://github.com/Microsoft/mssql-scripter

However, note that this project is no longer being maintained. That’s a real pity. I love the fact that Microsoft teams do put source code like this up on github. That means that you can:

  • Use it as a great learning resource
  • And if you’re keen, you can normally submit pull requests to improve the tools. However, as this project is no longer being maintained, they won’t be taking pull requests now.
  • Use it as the basis to create your own version of the tool.

To generate INSERT statements using it, you could use it like this:

mssql-scripter -S somesqlserver -d WideWorldImporters -U someuser -P somepassword –include-objects Customers –data-only

(Note that it would all be on a single line).

It does work still, but the recommendation is to use SSMS instead.

2026-11-04