Sqlpackage to create new database script RRS feed

  • Question

  • When using vsdbcmd, I was able to generate a full database creation script based on an existing dbschema file. However, I can't seem to find the right parameter set to do the same with SqlPackage

    Using vsdbcmd I provided /a:deploy /dsp:sql /model:model.dbschema /dsp:output.sql /p:TargetDatabase=DB

    Thursday, May 31, 2012 6:01 PM


  • Yes, the server name is required to perform the script action in this case.
    Thursday, May 31, 2012 8:47 PM

All replies

  • Hi Richard,

    You can do this with sqlpackage.exe's Script command, which is documented here: http://msdn.microsoft.com/en-us/library/hh550080(VS.103).aspx 

    Note that the schema artifact must be a a .dacpac, not a .dbschema file.  You can produce a .dacpac by building or snapshoting your SSDT project.

    Let me know if you run into any problems or questions,

    Janet Yeilding

    • Proposed as answer by Janet Yeilding Thursday, May 31, 2012 6:18 PM
    • Unproposed as answer by Richard Gavel Thursday, May 31, 2012 6:18 PM
    Thursday, May 31, 2012 6:18 PM
  • I understand using SqlPackage to create DIFFERENTIAL scripts between a source DACPAC (based off a build of the database project) and a target DACPAC. I've done that successfully. But what if the database doesn't exist yet? There is no target DACPAC.
    Thursday, May 31, 2012 6:20 PM
  • You target a server and provide a database name, instead.  I will look like this:

    sqlpackage /a:Script /sf:<path to your dacpac> /tsn:<server name> /tdn:<new database name> /op:<script output location>

    Thursday, May 31, 2012 8:28 PM
  • But I want to keep the functionality I had with vsdbcmd, which didn't need to connect to a database to generate the SQL to go from nothing to full database. The command line call I provided in the original post worked and didn't need a server name. Am I going to have to host an empty copy of something like SQL Express on my build box to point SqlPackage to?
    Thursday, May 31, 2012 8:33 PM
  • Yes, the server name is required to perform the script action in this case.
    Thursday, May 31, 2012 8:47 PM
  • I'm facing the same issue that Richard Gavel reported here and need to get the CREATE script (.sql file) to deploy on any server later. So I cannot provide a server name while generating a script. How do I solve this?



    Raj Muthusamy

    Wednesday, December 30, 2015 6:59 PM