1

I'd like to make a daily automatic creation of the creation script for a database in SQL Server 2008, meaning having a (bat, exe, ... whatever) that creates a text file with the very same output obtained by right-clicking on the database in SQL Management Studio and do Script database as... --> Create to... --> New Query window.

Any hint?

Thanks in advance,

Mauro

EDIT 1: We already used SMO but a couple of things are annoying

  • Needs compatibility pack in SQL Server 2008 (confirm?)
  • Some things were not created in script (some indexes and keys and in table creation schema is lost)

Best choice for me would something with a powershell script but any other idea is welcome!

3
  • 1
    There are probably a couple of third party tools out there that does exactly what you want. I use one of them and is a very happy user. Is it an option to buy something? Commented Jan 25, 2011 at 18:13
  • Hi Mikael, yes it is an option depending on price. Could you please share the tool you are using? Thx Commented Jan 26, 2011 at 7:33
  • 1
    I use AdaptSQL Diff adeptsql.com. There is is COM interface you can use if you want to automate the generation of SQL scripts. Commented Jan 26, 2011 at 9:02

1 Answer 1

3

You can use SMO. For example: http://www.sqlteam.com/article/scripting-database-objects-using-smo-updated (see the Scripting Objects section).

More info on SMO: http://msdn.microsoft.com/en-us/library/ms162169.aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.