1

Using Sql Server 2008 R2 (but I could possibly upgrade if required).

I want to generate scripts for the database structure as well as the data for a schema.

The Generate Scripts wizard does what I want but I need to be able to automate it (so needs to be called from T-SQL or alternatively external program).

How can I do this?

Wilhelm Kleu
  • 163
  • 1
  • 4
  • Data script can be generated by writing using TSQL like this http://www.connectsql.com/2010/12/sql-sqerver-generate-conditional-table.html – Aasim Abdullah Oct 16 '14 at 13:13
  • I think the best way is a PowerShell script, or other way to utilize SMO objects, like .Net app. – yahor Oct 16 '14 at 17:22

2 Answers2

0

I know that Red Gate SQL compare has a command line interface so you could write and schedule a batch file to generate the scripts. Details here

You could then use SQLcmd to execute the scripts.

James Anderson
  • 5,725
  • 2
  • 26
  • 43
0

Probably you want to try PowerShell scripting for this.

yahor
  • 131
  • 5