SQL Server – Generate Backwards Compatible CREATE DATABASE Script

compatibility-levelsql serverssms

I'm working on SQL Server 2016, and I want to deploy a database I have created to Sql Server 2012 SP1.

I found I was unable to create a backup in v2016 and restore to v2012. So instead in the v2016 version I:

  • Right click the DB
  • Select Tasks > Generate scripts
  • Script a CREATE statement for all objects

This kinda works… but I have to add a lot of objects manually. The database has tables/views/tvps/sps/scalar functions. Is there a way to script a create statement that is backwards compatible with older SQL Server versions?

Best Answer

I would advocate that you use Visual Studio to create a database project for this. You can set the target to be SQL 2012, then do a build and address any issues found. You can then deploy the schema to SQL 2012, and export/import your data. HTH.