Search code examples
sql-server-2012schemacommand-promptdata-dump

How to take SQL Server 2012 schema + data dump using command prompt


I have a database in SQL Server 2012. Now I am looking for some windows commands that will generate an .sql file for the schema[create statement] and another .sql file for the data[insert statement] of that database. I need to do this using command prompt. So I can't use the Generate Scripts option provided in SQL Server Management Studio.

Thanks in advance


Solution

  • The schema dump from command-line can be done using SQLPackage.exe. The command is -

    "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\sqlpackage.exe" /action:Extract /tf:<drive:\folder_name\file_name.dacpac> /SourceConnectionString:"Data Source=<server_name>;Initial Catalog=<db_name>;Integrated Security=SSPI;Persist Security Info=False; /su:<user_name> /sp=<password>

    If using windows authentication then input username = password = space. The file paths that contain spaces must be enclosed in quotation marks.

    See https://www.katieandemil.com/sqlpackage-exe-extract-dacpac-command-line?tab=article for more details.