azure-sql-databasebacpac

Import BACPAC into an _existing_ database


Is there a way to import a BACPAC file into an existing (empty) database? It looks like the PowerShell commands allow me to create new target databases only...

Is there a trick?


Solution

  • Yes you can import BACPAC file to an existing db but it should be absolutely empty.

    Use below command, run it from cmd or powershell. Note : location of sqlpackage.exe could be different on your machine.

    /tdn: is target database name here, which could be a pre-existing db but totaly empty. It's a good practice to create db before hand for larger db imports. SQL package.exe does make a new db for you if your db does not exists but then it caps its maximum size to 32gb unless specified otherwise.

    c:\"Program Files"\"Microsoft SQL Server"\150\DAC\bin\sqlpackage.exe 
        /a:Import 
        /sf:"bacpac file path" 
        /tsn:"targetsqlserver.database.windows.net" 
        /tdn:target_database_name
        /tu:username
    /tp:password