-1

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

Jinia
  • 1
  • 2
  • You can use PowerShell and SMO. Take a look at http://stackoverflow.com/questions/3488666/how-to-automate-script-generation-using-smo-in-sql-server. – Jeroen Mostert Nov 14 '14 at 12:50
  • Thanks @Jeroen Mostert but I wanted something like the answer below. Can u help with something like this for data dump also? – Jinia Nov 18 '14 at 11:03

1 Answers1

0

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.

Jinia
  • 1
  • 2