Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

808


Part V: Enterprise Data Management


You may wonder why the SQL Server Import and Export Wizard isn’t listed here. The answer is that the SQL Server
Import and Export Wizard isn’t supported for SQL Database yet. Microsoft is working on it. No timeframe has been
given as to when the Import/Export Wizard will support SQL Database, but support is defi nitely in the works.

The database you will use in these examples is from a scaled-down version of the
AdventureWorks database, which you can download from the website for this book.

Generate Scripts Wizard
You can use the Generate and Publish Scripts Wizard to create T-SQL scripts for SQL Server
databases and related objects within the selected database. You have probably used this
wizard, so this section doesn’t walk through it step-by-step; instead, the section briefl y
highlights a few steps in the wizard and points out the necessary options to effectively
work with SQL Database.

One of the differences between SQL Server 2012, SQL Server 2008 R2 and SQL Server 2008
(pertaining to object scripting) is a setting in the Advanced Scripting Options dialog as
you go through the wizard. This dialog includes two properties you can set regarding the
version of SQL Server for which you script database objects: Script for Server Version and
Script for the Database Engine Type. The Script for Server Version option lists the version of
SQL Server that the Generate and Publish Scripts wizard supports, which ranges from SQL
Server 2000 to SQL Server 2012.

The Script for the Database Engine Type property has two options you can choose from: Stand-
Alone Instance and SQL Database. The SQL database option works only with the SQL Server
2008 R2 Server and SQL Server 2008 R2 versions. For example, if you are using SQL Server
Management Studio for 2008 R2 and set the Script for Server version to SQL Server 2008 (non-
R2) and then set the Script for the Database Engine Type property to SQL database instance,
the Script for Server version property value automatically changes to SQL Server 2008 R2. In
SQL Server Management Studio for SQL Server 2012, the “Script for Server Version” will default
to SQL Server 2012 if you script for engine type “SQL Database.”

The Generate and Publish Scripts Wizard does a nice job of appropriately scripting objects
for SQL Database. The wizard checks for unsupported syntax and data types, and checks for
primary keys on each table. Thus, the following example sets SQL for Server Version to SQL
Server 2008 (non-R2) for several reasons. First, many people aren’t using SQL Server 2008 R2
or SQL Server 2012 and therefore don’t have the option to script for SQL Database. Second,
this exercise shows you the needed steps to get a script ready to run in SQL Database.

The examples in this chapter will use the Generate Scripts Wizard in SQL Server 2012,
but the steps in SQL Server 2008 R2 are similar. To start the Generate and Publish
Scripts Wizard in SQL Server Management Studio (SSMS), open Object Explorer, and
expand the Databases node. Select a database, right-mouse click on it, and then select
Tasks ➪ Generate Scripts from the context menu.

c31.indd 808c31.indd 808 7/31/2012 10:00:24 AM7/31/2012 10:00:24 AM


http://www.it-ebooks.info
Free download pdf