0% found this document useful (0 votes)
39 views

Implement and Maintain Indexes

Uploaded by

Nixon Muluh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Implement and Maintain Indexes

Uploaded by

Nixon Muluh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

7/23/2019 Print content

Administering Microsoft SQL Server 2012 Databases

Implement and Maintain Indexes

Introduction
Managing Indexes
Full Text Indexes
Summary

Introduction
The Implement and Maintain Indexes module provides you with the instruction and
server hardware to develop your hands on skills in the defined topics. This module
includes the following exercises:

Managing Indexes
Full Text Indexes

This lab now includes a SQL 2014 device, this means you can now carry out the
steps in SQL 2012 and SQL 2014. Notes have been included where any differences
in the steps may occur.

Lab time: It will take approximately 30 minutes to complete this lab.

Lab Diagram

During your session you will have access to the following lab configuration. Depending
on the exercises you may or may not use all of the devices, but they are shown here in the
layout to get an overall understanding of the topology of the lab.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 1/26
7/23/2019 Print content

Connecting to your lab

In this module you will be working on the following equipment to carry out the steps
defined in each exercise.

PLABSQL01 (Windows Server 2008 R2 - Domain Controller, SQL Server 1)


PLABSQL02 (Windows Server 2008 R2 - Domain Server, SQL Server 2)

For SQL 2014 you will use the following device:

PLABSQL03 (SQL Server 3)

To start, simply choose a device and click Power on. In some cases, the devices may
power on automatically.

For further information and technical support, please see our Help and Support
page.

Copyright Notice
This document and its content is copyright of Practice-IT - © Practice-IT 2014. All rights reserved. Any
redistribution or reproduction of part or all of the contents in any form is prohibited other than the
following:
1) You may print or download to a local hard disk extracts for your personal and non-commercial use
only.
2) You may copy the content to individual third parties for their personal use, but only if you
acknowledge the website as the source of the material. You may not, except with our express written

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 2/26
7/23/2019 Print content

permission, distribute or commercially exploit the content. Nor may you transmit it or store it in any
other website or other form of electronic retrieval system.

Exercise 1 - Managing Indexes


In this exercise, you will perform the tasks required to implement and maintain indexes.
To get a better understanding of this technology, please refer to your course material or
use your preferred search engine to research this topic in more detail.

SQL 2014 Note: To complete the following steps in SQL 2014, you will need to
replace the AdventureWorks2012 database name with AdventureWorks2014
in all the instances in text as well as code.

In this exercise, you will learn the following about Microsoft SQL Server 2012:

Inspecting the physical characteristics of indexes


Identifying fragmented indexes
Identifying unused indexes
Implementing indexes
Rebuilding vs reorganizing an index
Understanding column store indexes

Inspecting the Physical Characteristics of Indexes

To inspect the physical characteristics of indexes, perform the following steps:

Step 1
Ensure you have powered on the required devices and Connect to PLABSQL01.

SQL 2014 Note: To complete the following steps in SQL 2014, connect to
PLABSQL03.

On the desktop, double-click SQL Server Management Studio.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 3/26
7/23/2019 Print content

The Connect to Server dialog box is displayed.

Keep the default settings and click Connect.

Microsoft SQL Server Management Studio opens.

In Object Explorer, expand Databases, right-click AdventureWorks2012, select


Reports, select Standard Reports, and select Index Physical Statistics.

The Index Physical Statistics window is displayed in the right pane.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 4/26
7/23/2019 Print content

You will have to scroll down to get the complete list.

Identifying Fragmented Indexes

To identify fragmented indexes, perform the following steps:

Step 1
From SQL Server Management Studio.

In Object Explorer, expand Databases, right-click AdventureWorks2012, and


select New Query.

The new query window is displayed in the right pane.

In the query window, enter the following query and click Execute.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 5/26
7/23/2019 Print content

SELECT OBJECT_NAME(OBJECT_ID), index_id,index_type_desc,


avg_fragmentation_in_percent,page_count
FROM sys.dm_db_index_physical_stats
(DB_ID(N'AdventureWorks2012'), NULL, NULL, NULL ,
'SAMPLED')
ORDER BY avg_fragmentation_in_percent DESC

Identifying Unused Indexes

To identify unused indexes, perform the following steps:

Step 1
From SQL Server Management Studio.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 6/26
7/23/2019 Print content

In Object Explorer, expand Databases, right-click AdventureWorks2012, and


select New Query.

The new query window is displayed in the right pane.

Enter the following query in the new query window and click Execute.

SELECT OBJECT_SCHEMA_NAME(I.OBJECT_ID) AS SchemaName,


OBJECT_NAME(I.OBJECT_ID) AS ObjectName,
I.NAME AS IndexName
FROM sys.indexes I
WHERE
-- find out the indexes for user created tables
OBJECTPROPERTY(I.OBJECT_ID, 'IsUserTable') = 1
-- find out unused indexes
AND NOT EXISTS (
SELECT index_id
FROM sys.dm_db_index_usage_stats
WHERE OBJECT_ID = I.OBJECT_ID
AND I.index_id = index_id
-- limit our query only for the current db
AND database_id = DB_ID())
ORDER BY SchemaName, ObjectName, IndexName

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 7/26
7/23/2019 Print content

Implementing Indexes

To implement indexes, perform the following steps:

Step 1
From SQL Server Management Studio.

In Object Explorer, expand Databases, expand AdventureWorks2012, expand


Tables, expand HumanResources.Shift, expand Indexes, right-click
AK_Shift_Name, and select Reorganize.

The Reorganize Indexes dialog box is displayed. Click OK.

Rebuilding vs Reorganizing an Index

You can rebuild or reorganize an index. The rebuilding process is meant to be used when
there is heavier fragmentation. Reorganize, on the other hand, is used for light or
moderate level of fragmentation.
https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 8/26
7/23/2019 Print content

To rebuild or reorganize an index, perform the following steps:

Note: You will first run the reorganize process and then run the rebuild process.

Step 1
From SQL Server Management Studio.

In Object Explorer, expand Databases, expand AdventureWorks2012, expand


Tables, expand HumanResources.Shift, expand Indexes, and right-click
AK_Shift_Name, and select Reorganize.

The Reorganize Indexes dialog box is displayed. Click OK.

The dialog box automatically closes after the reorganizing process is complete.

Let’s now rebuild another index, assuming that it is heavily fragmented.

Right-click AK_Shift_StartTime and select Rebuild. The Rebuild Indexes dialog


box is displayed. Click OK.
https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 9/26
7/23/2019 Print content

Creating a Column Store Index

To create a column store index, perform the following steps:

Step 1
From SQL Server Management Studio.

In Object Explorer, expand Databases, expand AdventureWorks2012, expand


Tables, expand Person.Address, right-click Indexes, select New Index, and then
select Non-Clustered Index.

The New Index dialog box is displayed.

Enter PLAB.Person in the Index name text box by overwriting the existing name.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 10/26
7/23/2019 Print content

Click Add.

The Select Columns for ‘Person.Address’ dialog box is displayed.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 11/26
7/23/2019 Print content

Select AddressID, City, and ModifiedDate and click OK.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 12/26
7/23/2019 Print content

Click OK to close the New Index dialog box.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 13/26
7/23/2019 Print content

Expand Indexes under the Person.Address table.

Note that PLAB.Person is added.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 14/26
7/23/2019 Print content

Leave the devices you have powered on in their current state and proceed to the next
exercise.

Exercise 2 - Full Text Indexes


In this exercise, you will perform the tasks required to understanding how to create full
text indexes.

To get a better understanding of this technology, please refer to your course material or
use your preferred search engine to research this topic in more detail.

In this exercise, you will learn the following about Microsoft SQL Server 2012:

Creating full text indexes

Inspecting Physical Characteristics of Indexes

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 15/26
7/23/2019 Print content

To inspect physical characteristics of indexes, perform the following steps:

Step 1
Ensure you have powered on the required devices and Connect to PLABSQL01.

SQL 2014 Note: To complete the following steps in SQL 2014, connect to
PLABSQL03.

On the desktop, double-click SQL Server Management Studio.

The Connect to Server dialog box is displayed.

Keep the default settings and click Connect.

The Microsoft SQL Server Management Studio is now opened.

In Object Explorer, expand Databases, expand AdventureWorks2012, expand


Tables, right-click HumanResources.Shift, select Full-Text index, and then select
https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 16/26
7/23/2019 Print content

Define Full-Text Index.

The Full-Text Indexing Wizard is displayed. On the Welcome to the SQL Server
Full-Text Indexing Wizard, click Next.

On the Select an Index screen, keep the default values and click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 17/26
7/23/2019 Print content

On the Select Table Columns screen, select Name under the Available Columns
column and click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 18/26
7/23/2019 Print content

On the Select Change Tracking screen, Automatically is selected by default. Keep


the default setting and click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 19/26
7/23/2019 Print content

On the Select Catalog, Index FileGroup, and Stoplist screen, select Create a new
catalog and enter PLAB as the name in the Name textbox. Click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 20/26
7/23/2019 Print content

On the Define Population Schedules (Optional) screen, click Next.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 21/26
7/23/2019 Print content

On the Full-Text Indexing Wizard Description screen, click Finish.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 22/26
7/23/2019 Print content

The Full-Text Indexing Wizard Progress screen is displayed. Click Close.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 23/26
7/23/2019 Print content

Step 2
Right-click HumanResources.Shift, select Full-Text index, and then select Start
Full Population.

The Full Index Population dialog box is displayed. Click Close.

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 24/26
7/23/2019 Print content

Click Start and select Control.

Shutdown all virtual machines used in this lab, by using the power functions located in
the Tools bar before proceeding to the next module. Alternatively you can log out of the
lab platform.

Summary
In this exercise, you learnt the following about Microsoft SQL Server 2012:

Inspecting the physical characteristics of indexes


Identifying fragmented indexes
Identifying unused indexes
Implementing indexes
Rebuilding vs reorganizing an index

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 25/26
7/23/2019 Print content

Understanding column store indexes


Understanding rebuilding vs reorg and index
Creating full text indexes

Also try
Using the current lab setup, you can perform the following tasks at your own pace.

Finding the indexes that are not being utilized


Rebuilding an index
Finding fragmented indexes in a table

https://www.practice-labs.com/authenticated/vNext/vn-print-content.aspx 26/26

You might also like