Scripting MSSQL database schema and data

Recently ran into problems trying to export data from one MSSQL server to another. Turns out, you can't back up a database on a server running the 2012 copy and then restore it on a server running the 2008 copy.

To get arround this, I needed to script the entire database so that I could then run the script on the 2008 server and it was actually quite somple, I took the following steps:

In the MSSQL Management Console Object Explorer, right click on the database in question hover over 'Tasks' and then click 'Generate Scripts'.

Generate Scripts

It will allow you to generate scripts for one or all of the tables within your database. Just running through the wizard without changing any settings will only script the tables and this is where some people get confused.

On the first window, you need to select 'Script entire database and all database objects' then click 'Next >'.

Advanced Scripting Options

Once on the next screen, you need to make sure 'Output type' is set to 'Save scripts to a specific location', then choose a file name and click 'Advanced'.

If you're using anything older than 2008, your settings will look like this, you need to change 'Script Data' to 'True'.

alt text

However if you're using 2008 or newer, the option changes name and section, look for 'Types of data to script' , then change it to 'Schema and data'.

enter image description here


Published at

Tags: MSSQL

Luke Alderton

Comments

Share with
Tags
Latest Comments
By Mark Gentry on Windows Server 2019 - Change product key does nothing
20 Aug 2021, 03:30 AM
By Cathy on In-Place Upgrade for a Windows Server domain controller
31 Jul 2021, 18:28 PM
By Mr. Greymatter on Raspberry Pi - Running Java app on Raspbian
16 Feb 2021, 07:35 AM
By Mikko Seittenranta on Xamarin Forms multiple instances of same app open
16 Feb 2021, 04:34 AM
By Andrew on Auto/Custom height on Xamarin Forms WebView for Android and iOS
22 Jan 2021, 22:15 PM
By Nick on Raspberry Pi - Running Java app on Raspbian
14 Oct 2020, 19:37 PM
By Ivan on Fixed: Value cannot be null Parameter Name: source
15 Sep 2020, 19:47 PM
By Anand on Raspberry Pi - Bluetooth using Bluecove on Raspbian
7 Sep 2020, 16:53 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development