ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A...

44
ILTA UNIVERSITY Looking Into the New and Improved Functionality of Microsoft SQL 2008

Transcript of ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A...

Page 1: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

  

ILTA UNIVERSITY Looking Into the New and Improved Functionality of         

Microsoft SQL 2008      

 

 

 

 

 

 

 

 

 

 

 

              

Page 2: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

 

Page 3: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 1  

 

Table of Contents 

About this lab ................................................................................................................................................ 2 

About the Laboratory Environment .............................................................................................................. 2 

Lab 1: SQL Server Management Studio 2008 ............................................................................................... 3 

Exercise 1.  Explore the SSMS 2008 User Interface .................................................................................. 3 

Lab 2: Migrating Databases to SQL 2008 .................................................................................................... 13 

Exercise 1. Use Copy Database Wizard to Upgrade a SQL 2005 Database ............................................. 13 

Lab 3: SQL 2008 T‐SQL, Full Text, and CDC Features .................................................................................. 19 

Exercise 1.  Using Intellisense with Transact‐SQL ................................................................................... 19 

Exercise 2.  Using Full Text Indexing in SQL 2008 ................................................................................... 21 

Exercise 3.  Configuring the Change Data Capture Feature in SQL 2008 ................................................ 23 

Lab 4: SQL 2008 Reporting Services ............................................................................................................ 25 

Exercise 1. Configure SQL Server Reporting Services ............................................................................. 25 

Exercise 2.  Install SQL Report Builder 2.0 .............................................................................................. 28 

Exercise 3.  Create a simple report using Report Builder 2.0 ................................................................. 29 

Exercise 4. Updating our Chart ............................................................................................................... 34 

Exercise 5. Manage Report Subscriptions. .............................................................................................. 36 

Lab 5: Explore Policy Based Management Framework ............................................................................... 38 

Exercise 1. Create and Evaluate a New Policy ........................................................................................ 38 

Exercise 2. Backup the ILTADOCS Database and ReEvaluate our Policies .............................................. 41 

 

   

Page 4: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 2  

About this lab This Laboratory session is designed to familiarize you with the some of the new features of Microsoft SQL Server 2008.

We will take you through the latest interface features of SQL 2008, migrate legacy SQL databases, setup maintenance plans, and explore the new reporting module. Finally, we will setup a SQL Server policy to enforce corporate standards on the SQL environment.

This laboratory is targeted for the desktop administrator, and assumes that the participant has general experience with Microsoft SQL Server technologies. While experience with SQL 2000 or SQL 2005 is helpful, it is not required to complete the lab exercises.

About the Laboratory Environment You will be working in teams of two, sharing a workstation between members. The workstation has been configured with Virtual Server 2007 in order to house the virtual servers required for this lab.

We have configured two virtual machines as follows:

• SQLLAB: A Windows 2008 Server, with SQL Server 2008 preinstalled. This is the primary virtual machine that you will be using throughout this lab.

• SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual machine needs to be running in the background to complete the database migration exercises.

Both virtual machines have been setup in a Workgroup environment and exist on the same network.

Notes:

• You should use the administrator account for the laboratory tasks, except where noted.

• The password for administrator is Ilta09.

• DO NOT USE THE CTRL-ALT-DEL KEY SEQUENCE, AS IT WILL DISRUPT YOUR VIRTUAL SERVER SESSION. You should use the RIGHT ALT-DEL key sequence instead.

 

Page 5: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 3  

Lab 1: SQL Server Management Studio 2008

SQL Server Management Studio (SSMS) is an integrated environment for accessing, configuring, managing, administering, and developing all components of SQL Server.  SSMS combines a broad group of graphical tools with a number of rich script editors to provide access to SQL Server to developers and administrators.   

In this lab, we explore some of the new features of SSMS 2008. 

Exercise 1.  Explore the SSMS 2008 User Interface  

a. Launch the SQL Server Management Studio by clicking Start => All Programs => Microsoft SQL Server 2008 => SQL Server Management Studio.    

  

b. Fill in the Connect to Server form as follows:  

Server Type   Database Engine Database Engine   SQLLAB Authentication   SQL Server Authentication Login   sa Password   Ilta09 Remember Password   checked 

 Click Connect when finished. 

Page 6: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 4  

  

c. The SQL Server Management Studio is the main application that is used to manage your SQL environment.  Let’s begin exploring the interface by opening up the databases node, which contains all the databases that this SQL server houses.  Double Click SQLLAB => Databases => System Databases to look at the system databases for this native installation of SQL 2008.  

 

   

Page 7: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 5  

d. Click View => Object Explorer Details to see a list of all of the system databases on the right hand pane.  

  Notice that the Object Explorer Details pane now provides a columnar view of the databases.  Right‐click on the column headings in order to see all of the available options to display in this view. 

 

Page 8: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 6  

 Deselect the following items: Policy Health State, Compatibility Level, and Owner. Select the following items: Size, Last Backup Date, and Space Available.  You can rearrange or resize the columns as you see fit, such as in the following screenshot.  Furthermore notice that you can now see a view into all of your databases, their current size, the last backup operation, and the amount of space left in the databases – all in one screen!  

  

   

Page 9: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 7  

 e. Searching for database objects, such as stored procedures, triggers, views, or tables is 

much easier to do in SQL 2008 than in previous versions of MSSQL.  To execute a search, simply type a search term in the Search field in the Object Explorer Details screen.   

Try this, enter the search term %JOBS% in the Search field, and then hit ENTER to execute the search.  You should see a list of stored procedures similar to the graphic below. 

 

  This feature is very helpful if you are looking for a specific object, but you are not sure which database it exists in. 

   

Page 10: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 8  

f. It is now easier to view common information in your SQL databases from the SSMS interface.  Let’s take a look at some of these improvements in our Master database.  Double click the Master => Views => System Views.  Scroll down and right click the sys.databases view.   

  Note that there is now a feature to select the top 1000 rows, or edit the top 200 rows.  This is a great way to see or edit the contents of a table without inadvertently opening up tens of thousands of rows or locking the entire table.  These options are also configurable if you want to return a different number of rows for selecting or editing.  Go ahead and click the Select Top 1000 Rows option.  Notice that the SQL Query that returns the Top 1000 Rows is automatically formulated in the query screen, with the results in the results pane.  

 

Page 11: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 9  

g. SSMS now supports custom colors for different connection types.  While color coding a status bar may seem like a superficial feature, it is actually quite useful in terms of categorizing server types, highlighting important servers, or separating servers from the production and development environment.  To Setup custom colors, you need to edit the connection properties to your SQL Server(s).  We will create a new connection to our SQLLAB Server to show the custom colors features.  Begin by clicking View => Registered Servers.  Expand Database Engine => Local Server Groups.  Right Click Local Server Groups, and select New Server Registration.  Fill out the form as follows:  

Server Name  SQLLAB Authentication  SQL Server Authentication Login  sa Password  Ilta09 Remember Password  Checked Registered Server Name  SQLLAB2 

 

 

   

Page 12: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 10  

Click the Connection Properties tab, and click the Use custom color option.  Click Select, and then select a red color.   

 

Click Save when finished. 

NOTE: There are now two SQL Server registrations for the same server (SQLLAB). 

h. Let’s test out our new custom color.  Right Click the SQLLAB2 and click New Query.  Enter a password of Ilta09, and click Connect.  Note that the status bar in SSMS is now highlighted in red.  Now right click the sqllab server, and click New Query.  Notice that the new query status bar is highlighted in yellow (the default).    This has some benefits since you can easily distinguish between servers when running queries.  

i. SSMS 2008 supports a nifty feature where you can run SQL Queries on multiple servers at the same time.  To do this, right click the Local Server Group and select New Query.  Please note that the Local Server group contains two SQL Registrations, both to the same server.  We are using the same server in this exercise for illustrative purposes. 

   

Page 13: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 11  

 j. In the New Query window, type in the following SQL Query: 

 Select * from sysdatabases

k. Click the Execute button to run the query. 

Notice that the query is returned with a column heading of Server Name.    We will be taking a closer look at some of the new features of Transact SQL queries in a later exercise.   

Page 14: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 12  

 

l. The Activity Monitor in SQL 2008 has also been enhanced.  Let’s take a quick look at some of the new features.  Click the Object Explorer tab at the bottom of the SSMS.  Right Click the SQLLAB server, and then choose Activity Monitor.   

  Note that you can now see the overall health of the server, locked processes, and resource intensive queries.  

 

 

   

Page 15: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 13  

Lab 2: Migrating Databases to SQL 2008

There are several methods of bringing your databases into SQL 2008: 

• Backup your database in SQL 2000 or SQL 2005, and restore them on SQL 2008. 

• Perform an in‐place upgrade on the SQL Server where your databases exist. 

• Use the Copy Database Wizard. 

In this lab, we will be using the Copy Database Wizard to migrate and upgrade a SQL 2005 database to our new SQL 2008 environment. 

Exercise 1. Use Copy Database Wizard to Upgrade a SQL 2005 Database 

In this exercise we will use the SQL 2008 Copy Database Wizard to copy and upgrade a database to our SQL 2008 server.  For the purposes of this lab, we have created a sample database called ILTADOCS.  This database currently resides on a SQL 2005 server called SQL2005. 

a. If you haven’t done so, launch Microsoft SQL Server Management Studio by clicking Start => All Program => Microsoft SQL Server 2008 => Microsoft SQL Server Management Studio. 

b. Launch the Copy Database Wizard by right clicking the Management folder and clicking Copy Database…  The Copy Database Wizard should launch.  

   

Page 16: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 14  

c. Click Next.  The Select a Source Server screen should now display.  We would like to migrate the ILTADOCS database from the SQL2005 Source Server.  For the source server, type in SQL2005.  Click the Use SQL Server Authentication radio button, and type in sa for the username and Ilta09 for the password.  

  

d. Click Next.  The Select a Destination Server dialog should now display.  We would like to migrate this database to our newly installed SQL 2008 server.  Type in SQLLAB for the Source server.  Leave the Use Windows Authentication radio button checked.  

   

Page 17: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 15  

e.  Click Next.  In the Select a Transfer Method dialog box, click the Use the SQL Management Object Method radio button.  While the detach/attach method of migrating databases works well, it requires that the source database be taken off line.  

  

f. Click Next.  Click the Copy Checkbox next to the ILTADOCS database.  

   

Page 18: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 16  

g. Click Next.  The Destination Database dialog now shows you how the ILTADOCS database will look on the new server after migration.    

  

h. Click Next.  The Server Objects dialog lets you select additional objects for migration.  In our case, we do not want to migrate any other objects.  

   

Page 19: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 17  

i. Click Next. In the Configure the Package dialog, we can choose how to name our package, and how to record logging for the package.  The package created will be responsible for performing the database migration.  The defaults will work fine for our lab.  

  

j. Click Next.  Now we have the opportunity to schedule when this job should run.  In our case we want to run this package immediately.  

  

Page 20: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 18  

k.  Click Next.  

  

l. Click Finish to begin the migration.  

m. Close the Databases folder and then re‐open.  The ILTADOCS database should now be there (Note: you may need to force a refresh by right‐clicking on the Databases folder and selecting Refresh).   

 

Page 21: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 19  

Lab 3: SQL 2008 T-SQL, Full Text, and CDC Features

In this lab, we will look at some of the enhancements and features that SQL 2008 brings to the table.  We will primarily use the ILTADOCS database that we migrated in the previous lab for most of these exercises. 

The ILTADOCS database contains a simplified set of tables that loosely resembles the content that one would find in a typical document management system.  We have defined 4 different tables to represent metadata for documents as follows:  

 

If you have little familiarity with database design, the above figure may seem confusing.  To give a quick summary, there is a primary table called Documents which contains the metadata (i.e., DocNumber, DocName, etc) for each document record.  For the Client, Matter, and Author columns, there is a relationship to the Client, Matter, and DocUsers table.  Finally, there is relationship between the Client and Matter table as well. 

Exercise 1.  Using Intellisense with Transact­SQL Writing Transact‐SQL queries in previous versions of SQL was often a disorganized, error prone process, which may have resulted in unexpected or even disastrous consequences.  Proper syntax, using the correct terminology, and remembering the objects within our database schema were all difficult issues to overcome when writing queries. 

 

Page 22: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 20  

IntelliSense is a new feature of SQL 2008 which makes it easier to compose, read, and organize your SQL Queries.   

Some of the features of IntelliSense include: 

• Completing words as they are typed in a variable, command, or function once enough characters are typed so that it they can be uniquely identified.  

• Listing the available parameters required by a function or stored procedure.  

• Opening a list that provides available database objects and user‐defined variables that you have previously declared. 

We are going to write a few sample queries to look at these features. 

a. If you haven’t done so, launch Microsoft SQL Server Management Studio by clicking Start => All Program => Microsoft SQL Server 2008 => Microsoft SQL Server Management Studio.  

b. Navigate to the ILTADOCS database by double clicking it in SSMS.  Click the New Query button on the toolbar to open up a new query window.  

c. Let’s say we wanted to select some data from our documents table, but we weren’t sure which columns existed in the table.  Begin by typing the following SQL Statement:  Select from Documents D Note that when you started to type the statement, Intellisense began suggesting possible valid objects to you.  This is especially helpful when typing out the word Documents.  This is not a complete SQL statement, as we haven’t selected any columns to return.  We have only provided an alias for the Documents table, D.  

d. Go back in your statement before the word “from,” and type in the Alias D. 

 Typing in the table alias automatically brings up all of the columns of the table!  Let’s choose DocName from the list.  After selecting DocName, enter a comma, and use the same alias to select Type from the list. Your query should look as follows: 

Page 23: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 21  

 SELECT D.docname, D.type from Documents D  Click the Execute Query button to run the query.  You should now see a list of the document names and their types in our table.  Note the different document types.  

e. Let’s refine our query so we only see the pleadings by using a  where clause.  Go back to your previous query, and press ENTER after the last “D” to start a new line.  Type in:  WHERE D.type=’PLEAD’

f. Notice that Intellisense automatically grouped the two lines in the statement together, making it easier to read.  Execute the query when complete.  

g. Finally, let’s write a slightly more complex SQL query to see how Intellisense can help us out.  We will design a query that joins the documents, matter, and client tables to extract information.  Erase your previous query, and type in the following:  SELECT D.docname, D.docnumber, C.clientname, M.mattername from Documents D INNER JOIN Matter M on D.matter = M.matterID and D.client = M.parentID INNER JOIN Client C on D.client = C.clientID

Intellisense should have helped you pick the correct columns in our database, helped organize the query, and highlighted any typos.  

Exercise 2.  Using Full Text Indexing in SQL 2008 SQL Server 2008 provides the functionality for applications and users to issue full‐text queries against character‐based data in SQL Server tables.  These queries can include word or phrase searching, through a variety of data types.  Although databases in SQL Server 2008 are full‐text enabled by default, you must set up full‐text indexing capability on the columns of the tables that you want to access using the Full‐Text Engine. In this exercise, we will create a full text index for our documents table, and then run queries against them.   

a. The first step is to create a Full Text catalog on our ILTADOCS database.  A full‐text catalog is a logical concept that refers to a group of full‐text indexes for a specific database.  If you haven’t done so already, open up a query window by clicking the ILTADOCS database, and clicking the New Query button.  

b. To create a catalog, type in the following in the query window:  CREATE FULLTEXT CATALOG ILTADOCSFT

 Click the Execute button to create the Full Text Catalog named ILTADOCSFT 

Page 24: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 22  

c.  Another requirement in creating full‐text search is that the table must contain a unique, single‐column, non‐nullable index. The Full‐Text Engine requires this unique index to map each row in the table to a unique, compressible key. Unfortunately the Documents table does currently not contain a unique index.  To create an index on our table, erase the contents in the query window, and type the following:  CREATE UNIQUE INDEX ui_DocNumber ON Documents(DocNumber)

 Click the Execute button to create the unique index on DocNumber column in our Documents table.  Open Tables => DBO.Documents => Indexes and you should see the ui_DocNumber index.    

d. We are now ready to create our full text index.  Erase the contents in the query window, and type the following:  CREATE FULLTEXT INDEX ON Documents (

DocName, Author,Type )

KEY INDEX ui_DocNumber ON ILTADOCSFT WITH CHANGE_TRACKING AUTO

 This statement will create a full text index on the Documents table, indexing the DocName, Author, and Type columns.  We have configured the index to automatically populate and update by setting the Change_Tracking feature to Auto.  Click the Execute button to create the Full Text Index.    

e. Now that we have created a full text index, we can run a simple full text queries against it.  Erase the previous query, and type the following in the query window:  SELECT * FROM Documents WHERE FREETEXT(*, 'Criminal')  

 Click the Execute button to run the query.    You should have a number of results with the word “Criminal” in the document name. 

   

Page 25: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 23  

Exercise 3.  Configuring the Change Data Capture Feature in SQL 2008  

Change data capture (CDC) is a new feature of SQL 2008 that records insert, update, and delete activity applied to SQL Server tables.  SQL 2008 activity that is tracked is written to a mirrored table, which can easily be queried.  This feature can be particularly useful in Document Management environments where you need to record activity that is not natively handled by the software.   In this lab, you will enable and configure Change Data Capture and perform the activities to monitor how the data capture process works. 

a.  The first thing we will need to do is enable Change Data Capture in our database.  If you haven’t done so already, open up a query window by clicking the ILTADOCS database, and clicking the New Query button.  

b. To create a catalog, type in the following in the query window:  EXEC sp_cdc_enable_db

  Click the Execute button to enable change data capture.  

c. In SSMS, open up the ILTADOCS database, and navigate Tables => System Tables.  Under System Tables, you will now notice that there are several tables devoted to the CDC feature.    

d. We are now ready to enable CDC on our documents table. To do so, erase the previous query, and type in the following:  EXEC sys.sp_cdc_enable_table

@source_schema = N'dbo', @source_name = N'Documents', @role_name = N'cdc_Admin'

Click the Execute button to enable CDC on the documents table.  

e. Now that we’ve enabled CDC, let’s see it in action.  The first thing we will do is insert a new row in our table.  To do so, delete the previous query, and type in:  INSERT INTO Documents values (2000,'CDC Test Document Name','', '', '', '', '', '')

Click the Execute button to insert a new row in our Documents table. 

Page 26: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 24  

 f. Let’s delete that document we just created.  To do so, delete the previous query, and 

type in:  DELETE FROM DOCUMENTS WHERE DOCNUMBER = 2000

Click the Execute button to delete the document we just inserted.  

g. Let’s see what the CDC has recorded in terms of our changes to our documents table.  Delete the previous query, and type in:  SELECT * FROM CDC.DBO_DOCUMENTS_CT

Click the Execute button to look at the contents of the Documents CDC table.  

 You should now see two results – one for the insert, and one for the deletion.    Note:  For the __$operation column, 1 refers to a delete, 2 is an insert, 3 is the before image of an update, and 4 is the after image of an update. SELECT statements are not captured.  

 

 

Page 27: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 25  

Lab 4: SQL 2008 Reporting Services

SQL Server Reporting Services (SSRS) is a server‐based report generation tool that ships with SQL Server 2008.  SSRS can be used to author and generate many different types of reports within your SQL databases.  You can also use SSRS to e‐mail, subscribe, or create ad hoc reports. 

In this lab, we will configure SQL Server Reporting Services and create reports to highlight some of the new features of SQL 2008. 

Exercise 1. Configure SQL Server Reporting Services  

Before authoring reports in SSRS, we first need to configure some of the components to ensure proper connectivity.  In this exercise, you will use Reporting Services Configuration Manager to view and configure Reporting Services settings. Reporting Services Configuration Manager provides a comprehensive configuration tool that you can use to manage all aspects of the Reporting Services configuration. 

a. Launch the SQL Server Reporting Configuration by clicking Start => All Programs => Microsoft SQL Server 2008 => Configuration Tools => Reporting Services Configuration Manager.  The Connection Dialog should now launch.  

     

Page 28: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 26  

b.  Choose the default options and click Connect.  The Reporting Services Configuration Manager should now launch.  

c. Within this dialog, you can configure many aspects of Reporting Services, such as encryption, E‐Mail, the Reporting Services database, and scaling out the Reporting Engine.  In this case, we want to verify the Web Service URL is setup correctly so we can manage reports via a web client.  Click the Web Service URL in the left‐hand pane and verify that it points to http://sqllab:80/reportserver. 

 

d.  The Report Manager URL is where users can log in to create, modify, or view reports.  Click on the Report Manager URL link in the left‐hand pane, and verify that URLs: is set for http://SQLLAB:80/Reports. 

   

Page 29: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 27  

 e. Click the E‐Mail Settings link in the left‐hand pane to setup E‐Mail connectivity.   

Enter the E‐Mail settings as follows:  

Sender Address   [email protected] Current SMTP Delivery Address  Use SMTP Server SMTP Server  SQLLAB 

 

 

f. Click Apply when finished.  You may now exit the Configuration Manager by clicking Exit.  

g. We now need to make sure our SMTP Virtual Server is started to ensure correct E‐Mail connectivity.  To do so, launch Internet Information Services 6.0 by clicking Start => Administrative Tools => Internet Information Services (IIS) 6.0 Manager.  

h. Open up the SMTP Virtual Server by opening up the SQLLAB node.  Check to see if the SMTP Virtual Server is started –if there is a red X, it is stopped.  If so, start it by right‐clicking the SMTP Virtual Server, and then clicking Start. 

Page 30: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 28  

  

i. You can now Exit out of IIS 6.0. 

Now that we’ve updated and verified our settings, we are ready to create our first report. 

Exercise 2.  Install SQL Report Builder 2.0 The SQL Report Builder 2.0 is an add‐on feature to SQL Server 2008 that provides an intuitive report authoring environment for users.  It has been specifically enhanced to take advantage of many of the SQL Server 2008 reporting capabilities. 

a.  Install SQL Report Builder 2.0 by navigating to the installation files.  Launch Windows Explorer by clicking Start => All Programs => Accessories => Windows Explorer.  Click the Computer icon, and navigate to the C:\Lab Files\ReportBuilder directory.  Once there, double click the ReportBuilder installer file, followed by Run to begin installation.  

b. Click Next, click the I Accept radio button, click Next, Next, Next.  

c. For the Default target server URL line, enter http://SQLLAB:80/reportserver.  This is the URL that was referenced in the previous exercise.  

 Click Next to continue. 

Page 31: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 29  

 d. Click Install to begin the installation. 

 e. When the Installation completes, click Finish. 

Exercise 3.  Create a simple report using Report Builder 2.0 Now that we have install Report Builder 2.0, we will begin to create a simple report against our sample database, ILTADOCS. 

a. Launch Report Builder by clicking Start => All Programs => Microsoft SQL Server 2008 Report Builder 2.0 => Report Builder 2.0. 

  

b.  We will create a chart view report that shows all of the users in the database, followed by how many documents each has authored, grouped by the types of documents.  Click the Chart link within the editing window to launch the Chart Wizard.  

c. We first need to create a data source to our ILTADOCS database.  To do so, click the New… button.  

Page 32: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 30  

d. For the Datasource Name, type in ILTADOCS.  Click the Build… button to create a connection string to our ILTADOCS database.  

e. In the Connection Properties Screen, type in SQLLAB for the server name, select the SQL Server Authentication radio button, and type in sa for the user account, and Ilta09 for the password.  Make sure the Save my Password option is checked.  In the Connect to a database section, click the drop down arrow in the select or enter a database name option, and choose the ILTADOCS database.  Click OK when finished.  

  Your Datasource Properties should look like the above picture.  If not, repeat steps d and e in this section.  Once everything looks fine, click Credentials in the left‐hand pane. 

   

Page 33: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 31  

 f.  We now specify that the logged in user will be used to connect to the database.  Click 

the use this user name and password option.  Use sa for the user name and Ilta09 for the password.  

  

g. Click OK when finished.  You will now go back to the Choose a connection to a data source screen.  Click the data source that you just selected, and click Next to go to the Design a query dialog.  

 

Page 34: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 32  

 h. We will now create a simple query for our report.  Expand the dbo node, followed by 

the Tables node, and select the Documents table.  Select only the following column names: DocNumber, Author, and Type.  Click the Run Query button to verify that the correct data is being returned.  

  

Click Next.  

i. Choose a Column chart in the Chart Type dialog, and click Next.              

Page 35: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 33  

j. Drag the Author field to the Categories section, Type in the series section, and the DocNumber field to the Values section.  Click the Drop Down arrow next to the DocNumber field you just dragged, and change it to Count.  

  Click Next.  

k. Click Ocean for the chart style.  And click Finish. 

 

Page 36: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 34  

 l. Congratulations!  You finished your first report!  Click the Run button on the main 

toolbar in the upper left hand side to verify your results.  As you can see, the chart still needs a little tweaking.  We will be updating this report in the next exercise. 

 

Exercise 4. Updating our Chart  

Now that we have a basic report created, we need to make some modifications to make it more readable. 

a. If you are not there yet, go to the design view of the chart by clicking the Design button on the toolbar.  

b. The first thing we need to do is enlarge our chart.  Click the middle of the chart to highlight it.  Drag the lower right hand node until it fills the screen.  

     

Page 37: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 35  

c. We now need to change the X‐Axis interval settings.  Right click the area underneath the chart where it says “Author A Author B Author C…”, and click Axis Properties.  For the Interval property under Set axis scale and type type in 1.    

  Click OK. This will force chart to show all of our authors.  

d. Let’s update some of the chart descriptions.  Double Click the Chart Title.  Highlight the text, delete it, and replace it with “Number of Documents by Author”.  Do the same thing for the Axis Titles.  For the X Axis title on the bottom of the chart, name it “Author”.  For the Y Axis title on the left of the chart, name it “Number”.  

e. Now click the Run button on the toolbar to generate the report.  

f. This looks much better.  Let’s go ahead and save the report by clicking the pearl in the upper left hand corner, and clicking Save.  Call the report “DocumentsbyAuthor” and save it into the default location (http://SQLLAB/Reportserver)      

Page 38: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 36  

Exercise 5. Manage Report Subscriptions. Now that we have created a report, we would like to automatically run and deliver this report via e‐mail. 

a. Report subscriptions can be managed by the SSRS web client.  You can access the reports module by opening Internet Explorer and browsing to http://SQLLAB/reports.  If prompted, enter in administrator / Ilta09 for the username / password.  

  

b. The DocumentsByAuthor report that you saved in the last exercise should now be available.  Click on it to run it.  Users without the Report Builder client can easily access these reports on demand through the SSRS web client.  

c. Click the Subscriptions Tab, and click New Subscription to setup a new subscription.  

d. Leave all options as default except for the following properties: Delivered by: E‐Mail To: [email protected] Comment:  Type in “Click the link to show the number of documents per author”  

e. Click Select Schedule. 

Page 39: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 37  

 f. In the Daily Schedule section, select Every weekday, set the time to two minutes from 

the time currently displayed in the clock in the notification area on the task bar, and then click OK.  

g. Click OK to complete the subscription.  

h. Wait two minutes, or until the time that you scheduled the subscription to run.  Then refresh the web page.  Note the Last Run value for the subscription.  

i. Let’s take a look at the E‐Mail for the subscription we just created.  Open up Windows Explorer by clicking Start => All Programs => Accessories => Windows Explorer.  Click the Computer icon, and navigate to the C:\InetPub\Mailroot\Drop directory.  Double click the E‐Mail, and verify that the chart is there, along with a link to the report. 

   

Page 40: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 38  

 

Lab 5: Explore Policy Based Management Framework

Policy‐Based Management is a new feature in SQL Server 2008.  It allows you to define and enforce policies on database instances, objects and SQL Servers across the enterprise.   Policies can be used to a number of different things in your SQL Enterprise, including the enforcement of naming conventions, verification of correct database options, and ensuring SQL Server configuration options are in compliance.   

There are a number of terms to be understood with Policy‐Based Management: 

• Target ‐ an entity that is managed by Policy‐Based management; e.g. a database, a table, an index, etc.  

• Facet ‐ a predefined set of properties that can be managed  • Condition ‐ a property expression that evaluates to True or False  • Policy ‐ a condition to be checked and/or enforced 

The most challenging part of creating an effective database policy system is deciding what exactly it is you want to create policies for.   In this lab, we will configure SQL Server Policies to ensure that database backups are being handled regularly. 

Exercise 1. Create and Evaluate a New Policy 

a. The first step in creating the policy is to create a condition. To do this launch SQL Server Management Studio and navigate to the Management => Policy Management => Conditions  node. 

b. We now want to create a condition that can detect whether a database has been backed up.  Start by right‐clicking on the Conditions folder and click select New Condition... In the Create New Condition dialog box, enter a name of Last Backup Date, and pick the Database facet.

c. Let’s define an expression that can detect databases that haven’t been backed up. In the Expression area, click the Field Box, and select @LastBackupDate. Click >= in the operator box, and then click the … in the Value field. The Advanced Edit box should now pop up. Type in the following for the cell value: DATEADD(‘DAY’,-1,GetDate())

Page 41: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 39  

When finished, close the dialog box.  

  Click OK when your condition is complete.  

d. Now right click the Policies node under Management in SSMS, and click New Policy…   Let’s name it Check Database Backups.  In the Check condition field, choose the Last Backup Date condition we previously created.  For the targets, leave the default of Every Database.  For now, we will leave the Evaluation Mode as On Demand.  

  Click OK to complete the policy. 

Page 42: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 40  

 e. We are ready to evaluate our Policy.  To do so, right click the Check Database Backups 

policy and select Evaluate.  

  You should now see that the policy throws three errors, one for each database in our system that has not been backed up. 

   

Page 43: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 41  

Exercise 2. Backup the ILTADOCS Database and ReEvaluate our Policies a. We will now perform a manual backup of the ILTADOCS database as our policy 

recommends.   In SSMS, Right Click the ILTADOCS database and select  Tasks => Backup… 

 

b. For our lab, the defaults will work fine for us.  Click OK to perform the backup.  It should complete relatively quickly.  

   

Page 44: ILTA UNIVERSITYilta.personifycloud.com/webfiles/productfiles/897/ILTAU2008Lab.pdf · • SQL2005: A Windows 2003 SP2 Server, with SQL Server 2005 preinstalled. This virtual This virtual

ILTA UNIVERSITY 

 

ILTA09 SQL2008 University Lab Session  Page 42  

c. To double check that the backup is correct, Launch Windows Explorer and navigate to the C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\Backup directory.  

d. Make sure you see the physical Backup file ILTADOCS.BAK.  

e. Now that we’ve backed up the database, let’s see if our policy results change.  Switch back to SQL Server Management Studio, and re‐evaluate the Check Database Backup policy.  You should see the following results (after resizing the column widths).  

  

f. Let’s make another change to our policy so that it runs on a schedule, rather than on‐demand.  Right click the Check Database Backup policy, and select Properties.  In the Evaluation Mode dialog, select On Schedule. We are now going to choose a pre‐existing schedule.  Click the Pick button, and choose the “Every 5 minutes” schedule (ID 2).  

  Click OK when finished.  

g.  We now need to enable the policy.  To do so, right click the Check Database Backup policy, and choose  Enable.  Every 5 minutes, the policy will evaluate and determine which databases have not been backed up in the last day.  Events will automatically be sent to the event viewer.  It is possible to create an alert that will automatically backup our databases if the policy evaluation fails.  Furthermore, this policy can apply to all SQL 2008 servers as well, so you can enforce database backups in one policy throughout your organization.