Quick Azure SQL tip for on-premises migrators: use Entity Framework to generate your Azure SQL compatible database creation script

Posted: (EET/GMT+2)

 

So, you've got your complex, local SQL Server database, and you want to quickly get a script that can create an empty database in Azure with a similar structure. I've blogged before on how you can do this manually, but today, I wanted to share a quick tip on how to get going even faster.

If you have an on-premises SQL Server database, you can definitely use SQL Server Management Studio to generate the script for you. But, this script won't work directly with SQL Server on Azure (or Azure SQL).

Visual Studio and Entity Framework can come to the rescue here. Especially if your application is already using Entity Framework, you can get the script very easily: open up your model designed by double-clicking your EDMX file, and then choosing the command "Generate Database from Model". This useful command displays a dialog box with the script shown.

You don't need to complete the wizard. Instead, simply right-click the SQL script (the text area), choose Select All and then again Copy. You've got an Azure compatible script in your clipboard, ready for action elsewhere!

Hope this helps!