SlideShare une entreprise Scribd logo
1  sur  17
Querying and Managing Data using SQL Server 2005
Objectives


                In this session, you will learn to:
                   Create and manage indexes




     Ver. 1.0                        Session 10       Slide 1 of 17
Querying and Managing Data using SQL Server 2005
Identifying Type of Indexes


                Flash presentation: Implementing Indexes
                Index:
                   Is a data structure associated with a table
                   Enables quick access to data
                   Accelerates queries that join tables, and perform sorting and
                   grouping
                   Can be used to enforce uniqueness of rows
                   Contains a collection of keys and pointers stored in B-Tree in
                   the memory




     Ver. 1.0                        Session 10                            Slide 2 of 17
Querying and Managing Data using SQL Server 2005
Identifying Type of Indexes (Contd.)


                Indexes are of two types:
                 – Clustered index: Sorts and stores the data rows in the table
                   based on their key values.
                 – Nonclustered index: Contains the index key values and row
                   locators that point to the storage location of the data but the
                   physical order of rows is different.




     Ver. 1.0                        Session 10                             Slide 3 of 17
Querying and Managing Data using SQL Server 2005
Identifying Type of Indexes (Contd.)


                Working of a Clustered Index:




     Ver. 1.0                     Session 10    Slide 4 of 17
Querying and Managing Data using SQL Server 2005
Identifying Type of Indexes (Contd.)


                Working of a NonClustered Index:




     Ver. 1.0                     Session 10       Slide 5 of 17
Querying and Managing Data using SQL Server 2005
Creating Indexes


                Index:
                   Is created on the most frequently queried column in tables or
                   views
                   Based on two or more columns is called a composite index
                   Can be created by using the CREATE INDEX statement




     Ver. 1.0                       Session 10                            Slide 6 of 17
Querying and Managing Data using SQL Server 2005
Creating Indexes (Contd.)


                Syntax:
                 CREATE [UNIQUE][CLUSTERED | NONCLUSTERED]
                 INDEX
                 index_name
                 ON [{database_name.[schema_name]. |
                 schema_name.}]
                 {table_or_view_name}(column [ASC | DESC]
                 [,...n])
                 [INCLUDE (column_name [,...n])]
                 [WITH(<relational_index_option>[,...n])]
                 [ON
                 {partition_scheme_name(column_name[,...n])
                 | filegroup_name | DEFAULT}]

     Ver. 1.0                 Session 10               Slide 7 of 17
Querying and Managing Data using SQL Server 2005
Creating Indexes (Contd.)


                 <relation_index_option>::= {PAD_INDEX = {ON
                 | OFF}
                 | FILLFACTOR = fillfactor | SORT_IN_TEMPDB
                 = {ON | OFF}
                 | IGNORE_DUP_KEY = {ON | OFF}
                 |STATISTICS_NO_RECOMPUTE = {ON | OFF}
                 | DROP_EXISTING = {ON | OFF} | ONLINE = {ON
                 | OFF}
                Let’s see how…




     Ver. 1.0                 Session 10               Slide 8 of 17
Querying and Managing Data using SQL Server 2005
Creating XML Indexes


                XML Index:
                   Can be created on columns storing XML data values
                   Supports indexing only on a single XML column
                   Is of two types:
                      Primary XML index
                      Secondary XML index




     Ver. 1.0                      Session 10                          Slide 9 of 17
Querying and Managing Data using SQL Server 2005
Just a minute


                Which type of index implements physical sorting of data?




                Answer:
                   Clustered index




     Ver. 1.0                        Session 10                    Slide 10 of 17
Querying and Managing Data using SQL Server 2005
Just a minute


                Which type of an XML index is created first on the table?




                Answer:
                   Primary XML index




     Ver. 1.0                      Session 10                        Slide 11 of 17
Querying and Managing Data using SQL Server 2005
Just a minute


                Which of the following is used to specify the percentage of
                space to be used for each index page?
                 1.   Fill Factor
                 2.   Pad Index
                 3.   Path Index
                 4.   Value Index




                Answer:
                 1. Fill Factor




     Ver. 1.0                       Session 10                       Slide 12 of 17
Querying and Managing Data using SQL Server 2005
Managing Indexes


               Involves:
                  Disabling indexes
                  Enabling indexes
                  Renaming indexes
                  Dropping indexes
                  Optimizing indexes
               Let’s see how…




    Ver. 1.0                      Session 10   Slide 13 of 17
Querying and Managing Data using SQL Server 2005
Demo: Creating Indexes


                Problem Statement:
                   The production manager of the AdventureWorks, Inc. needs to
                   frequently view data from the Product table in the Production
                   schema. He needs to frequently search for data based on the
                   product number.
                   The Product table contains a large volume of data, and
                   therefore the query takes time to execute. To reduce the time
                   taken in the execution of the query, you need to suggest a
                   solution to improve performance. For this, you need to check
                   the performance of the query before and after applying the
                   suggested solution.




     Ver. 1.0                       Session 10                          Slide 14 of 17
Querying and Managing Data using SQL Server 2005
Demo: Creating Indexes (Contd.)


                Solution:
                   To solve the preceding problem, you can apply an index on the
                   column on which data is frequently searched. To apply an
                   index, you need to perform the following tasks:
                    1. Identify the column to be indexed.
                    2. Enable the display of query execution plan.
                    3. Check the I/O cost of the query.
                    4. Create an index to improve performance.
                    5. Verify the improvement in query execution.




     Ver. 1.0                         Session 10                        Slide 15 of 17
Querying and Managing Data using SQL Server 2005
Summary


               In this session, you learned that:
                  Indexes are created to enhance the performance of queries.
                  There are two types of indexes, clustered and nonclustered.
                  Indexes are created by using the CREATE INDEX statement
                  Clustered indexes should be built on an attribute whose values
                  are unique and do not change often. Data is physically sorted
                  in a clustered index.
                  In a nonclustered index, the physical order of rows is not the
                  same as that of the index order.
                  A nonclustered index is the default index that is created with
                  the CREATE INDEX command.




    Ver. 1.0                       Session 10                           Slide 16 of 17
Querying and Managing Data using SQL Server 2005
Summary


               An XML index is built on columns with the XML data type.
               The common index maintenance tasks include disabling,
               enabling, renaming, and dropping an index.




    Ver. 1.0                    Session 10                          Slide 17 of 17

Contenu connexe

Tendances

SQL Sevrer 2008 R2 Overview
SQL Sevrer 2008 R2 OverviewSQL Sevrer 2008 R2 Overview
SQL Sevrer 2008 R2 Overview
Mark Kromer
 
10 qmds2005 session14
10 qmds2005 session1410 qmds2005 session14
10 qmds2005 session14
Niit Care
 
Download Presentation
Download PresentationDownload Presentation
Download Presentation
webhostingguy
 

Tendances (14)

SQL Sevrer 2008 R2 Overview
SQL Sevrer 2008 R2 OverviewSQL Sevrer 2008 R2 Overview
SQL Sevrer 2008 R2 Overview
 
10 qmds2005 session14
10 qmds2005 session1410 qmds2005 session14
10 qmds2005 session14
 
Sql views
Sql viewsSql views
Sql views
 
What's new in SQL Server 2012 for philly code camp 2012.1
What's new in SQL Server 2012 for philly code camp 2012.1What's new in SQL Server 2012 for philly code camp 2012.1
What's new in SQL Server 2012 for philly code camp 2012.1
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Sql ch 13 - sql-views
Sql ch 13 - sql-viewsSql ch 13 - sql-views
Sql ch 13 - sql-views
 
Download Presentation
Download PresentationDownload Presentation
Download Presentation
 
Oracle Database View
Oracle Database ViewOracle Database View
Oracle Database View
 
SQL212 Oracle SQL Manual
SQL212 Oracle SQL ManualSQL212 Oracle SQL Manual
SQL212 Oracle SQL Manual
 
MS Sql Server: Creating Views
MS Sql Server: Creating ViewsMS Sql Server: Creating Views
MS Sql Server: Creating Views
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
 
SQL Server Views
SQL Server ViewsSQL Server Views
SQL Server Views
 
SQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL QueriesSQL201S Accelerated Introduction to MySQL Queries
SQL201S Accelerated Introduction to MySQL Queries
 
ssssss
ssssssssssss
ssssss
 

Similaire à 07 qmds2005 session10

03 qmds2005 session03
03 qmds2005 session0303 qmds2005 session03
03 qmds2005 session03
Niit Care
 
05 qmds2005 session07
05 qmds2005 session0705 qmds2005 session07
05 qmds2005 session07
Niit Care
 
09 qmds2005 session13
09 qmds2005 session1309 qmds2005 session13
09 qmds2005 session13
Niit Care
 
Sql server indexed views speed up your select queries part 1 - code-projec
Sql server indexed views   speed up your select queries  part 1 - code-projecSql server indexed views   speed up your select queries  part 1 - code-projec
Sql server indexed views speed up your select queries part 1 - code-projec
Kaing Menglieng
 
Lesson10
Lesson10Lesson10
Lesson10
renguzi
 
Top 20 SQL interview questions.pdf
Top 20 SQL interview questions.pdfTop 20 SQL interview questions.pdf
Top 20 SQL interview questions.pdf
AnanthReddy38
 
SQL Interview Questions and Answers for Business Analyst
SQL Interview Questions and Answers for Business AnalystSQL Interview Questions and Answers for Business Analyst
SQL Interview Questions and Answers for Business Analyst
HireQuotient
 

Similaire à 07 qmds2005 session10 (20)

03 qmds2005 session03
03 qmds2005 session0303 qmds2005 session03
03 qmds2005 session03
 
05 qmds2005 session07
05 qmds2005 session0705 qmds2005 session07
05 qmds2005 session07
 
Sql xp 07
Sql xp 07Sql xp 07
Sql xp 07
 
09 qmds2005 session13
09 qmds2005 session1309 qmds2005 session13
09 qmds2005 session13
 
Sql server indexed views speed up your select queries part 1 - code-projec
Sql server indexed views   speed up your select queries  part 1 - code-projecSql server indexed views   speed up your select queries  part 1 - code-projec
Sql server indexed views speed up your select queries part 1 - code-projec
 
FREE Sql Server syllabus
FREE Sql Server syllabusFREE Sql Server syllabus
FREE Sql Server syllabus
 
6232 b 04
6232 b 046232 b 04
6232 b 04
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsOracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
 
Sage 300 ERP: Technical Tour of Diagnostic Tools
Sage 300 ERP: Technical Tour of Diagnostic ToolsSage 300 ERP: Technical Tour of Diagnostic Tools
Sage 300 ERP: Technical Tour of Diagnostic Tools
 
Ebook11
Ebook11Ebook11
Ebook11
 
Oracle SQL Training in Chennai, Tambaram
Oracle SQL Training in Chennai, TambaramOracle SQL Training in Chennai, Tambaram
Oracle SQL Training in Chennai, Tambaram
 
Lesson10
Lesson10Lesson10
Lesson10
 
MySQL New Features -- Sunshine PHP 2020 Presentation
MySQL New Features -- Sunshine PHP 2020 PresentationMySQL New Features -- Sunshine PHP 2020 Presentation
MySQL New Features -- Sunshine PHP 2020 Presentation
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
Rapid SQL Datasheet - The Intelligent IDE for SQL Development
Rapid SQL Datasheet - The Intelligent IDE for SQL DevelopmentRapid SQL Datasheet - The Intelligent IDE for SQL Development
Rapid SQL Datasheet - The Intelligent IDE for SQL Development
 
Top 20 SQL interview questions.pdf
Top 20 SQL interview questions.pdfTop 20 SQL interview questions.pdf
Top 20 SQL interview questions.pdf
 
Access tips access and sql part 1 setting the sql scene
Access tips  access and sql part 1  setting the sql sceneAccess tips  access and sql part 1  setting the sql scene
Access tips access and sql part 1 setting the sql scene
 
SQL Interview Questions and Answers for Business Analyst
SQL Interview Questions and Answers for Business AnalystSQL Interview Questions and Answers for Business Analyst
SQL Interview Questions and Answers for Business Analyst
 
70487.pdf
70487.pdf70487.pdf
70487.pdf
 
Module08
Module08Module08
Module08
 

Plus de Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

07 qmds2005 session10

  • 1. Querying and Managing Data using SQL Server 2005 Objectives In this session, you will learn to: Create and manage indexes Ver. 1.0 Session 10 Slide 1 of 17
  • 2. Querying and Managing Data using SQL Server 2005 Identifying Type of Indexes Flash presentation: Implementing Indexes Index: Is a data structure associated with a table Enables quick access to data Accelerates queries that join tables, and perform sorting and grouping Can be used to enforce uniqueness of rows Contains a collection of keys and pointers stored in B-Tree in the memory Ver. 1.0 Session 10 Slide 2 of 17
  • 3. Querying and Managing Data using SQL Server 2005 Identifying Type of Indexes (Contd.) Indexes are of two types: – Clustered index: Sorts and stores the data rows in the table based on their key values. – Nonclustered index: Contains the index key values and row locators that point to the storage location of the data but the physical order of rows is different. Ver. 1.0 Session 10 Slide 3 of 17
  • 4. Querying and Managing Data using SQL Server 2005 Identifying Type of Indexes (Contd.) Working of a Clustered Index: Ver. 1.0 Session 10 Slide 4 of 17
  • 5. Querying and Managing Data using SQL Server 2005 Identifying Type of Indexes (Contd.) Working of a NonClustered Index: Ver. 1.0 Session 10 Slide 5 of 17
  • 6. Querying and Managing Data using SQL Server 2005 Creating Indexes Index: Is created on the most frequently queried column in tables or views Based on two or more columns is called a composite index Can be created by using the CREATE INDEX statement Ver. 1.0 Session 10 Slide 6 of 17
  • 7. Querying and Managing Data using SQL Server 2005 Creating Indexes (Contd.) Syntax: CREATE [UNIQUE][CLUSTERED | NONCLUSTERED] INDEX index_name ON [{database_name.[schema_name]. | schema_name.}] {table_or_view_name}(column [ASC | DESC] [,...n]) [INCLUDE (column_name [,...n])] [WITH(<relational_index_option>[,...n])] [ON {partition_scheme_name(column_name[,...n]) | filegroup_name | DEFAULT}] Ver. 1.0 Session 10 Slide 7 of 17
  • 8. Querying and Managing Data using SQL Server 2005 Creating Indexes (Contd.) <relation_index_option>::= {PAD_INDEX = {ON | OFF} | FILLFACTOR = fillfactor | SORT_IN_TEMPDB = {ON | OFF} | IGNORE_DUP_KEY = {ON | OFF} |STATISTICS_NO_RECOMPUTE = {ON | OFF} | DROP_EXISTING = {ON | OFF} | ONLINE = {ON | OFF} Let’s see how… Ver. 1.0 Session 10 Slide 8 of 17
  • 9. Querying and Managing Data using SQL Server 2005 Creating XML Indexes XML Index: Can be created on columns storing XML data values Supports indexing only on a single XML column Is of two types: Primary XML index Secondary XML index Ver. 1.0 Session 10 Slide 9 of 17
  • 10. Querying and Managing Data using SQL Server 2005 Just a minute Which type of index implements physical sorting of data? Answer: Clustered index Ver. 1.0 Session 10 Slide 10 of 17
  • 11. Querying and Managing Data using SQL Server 2005 Just a minute Which type of an XML index is created first on the table? Answer: Primary XML index Ver. 1.0 Session 10 Slide 11 of 17
  • 12. Querying and Managing Data using SQL Server 2005 Just a minute Which of the following is used to specify the percentage of space to be used for each index page? 1. Fill Factor 2. Pad Index 3. Path Index 4. Value Index Answer: 1. Fill Factor Ver. 1.0 Session 10 Slide 12 of 17
  • 13. Querying and Managing Data using SQL Server 2005 Managing Indexes Involves: Disabling indexes Enabling indexes Renaming indexes Dropping indexes Optimizing indexes Let’s see how… Ver. 1.0 Session 10 Slide 13 of 17
  • 14. Querying and Managing Data using SQL Server 2005 Demo: Creating Indexes Problem Statement: The production manager of the AdventureWorks, Inc. needs to frequently view data from the Product table in the Production schema. He needs to frequently search for data based on the product number. The Product table contains a large volume of data, and therefore the query takes time to execute. To reduce the time taken in the execution of the query, you need to suggest a solution to improve performance. For this, you need to check the performance of the query before and after applying the suggested solution. Ver. 1.0 Session 10 Slide 14 of 17
  • 15. Querying and Managing Data using SQL Server 2005 Demo: Creating Indexes (Contd.) Solution: To solve the preceding problem, you can apply an index on the column on which data is frequently searched. To apply an index, you need to perform the following tasks: 1. Identify the column to be indexed. 2. Enable the display of query execution plan. 3. Check the I/O cost of the query. 4. Create an index to improve performance. 5. Verify the improvement in query execution. Ver. 1.0 Session 10 Slide 15 of 17
  • 16. Querying and Managing Data using SQL Server 2005 Summary In this session, you learned that: Indexes are created to enhance the performance of queries. There are two types of indexes, clustered and nonclustered. Indexes are created by using the CREATE INDEX statement Clustered indexes should be built on an attribute whose values are unique and do not change often. Data is physically sorted in a clustered index. In a nonclustered index, the physical order of rows is not the same as that of the index order. A nonclustered index is the default index that is created with the CREATE INDEX command. Ver. 1.0 Session 10 Slide 16 of 17
  • 17. Querying and Managing Data using SQL Server 2005 Summary An XML index is built on columns with the XML data type. The common index maintenance tasks include disabling, enabling, renaming, and dropping an index. Ver. 1.0 Session 10 Slide 17 of 17

Notes de l'éditeur

  1. Begin the session by sharing the objectives with the students.
  2. In this topic, you need to explain the concept of indexes to the students. While teaching the topic, you need to stress on the following points: Importance of naming conventions while creating indexes. Advantages of using indexes. Creating appropriate indexes for appropriate columns. Mention that indexes are used to speed up queries and are created on columns that are used in joins, the WHERE clause, the ORDER BY clause, or the GROUP BY clause. Additional Inputs If a primary key constraint is not created, then a unique clustered index can be used to implement the primary key and entity integrity. However, a foreign key constraint cannot reference such a column since a primary key constraint is not defined. However, in such cases, referential integrity can be implemented from the child table by using a trigger. Creating multiple indexes on a column is not a good practice. Indexes created by creation of constraints like the Primary key or Unique cannot be dropped by using the DROP INDEX statement. To drop these indexes, you need to drop the constraint. In a SELECT statement without a WHERE clause, indexes belonging to the column mentioned first in the select list are used. A unique index enforces uniqueness on the column for which it is mentioned. If nulls are allowed, it will allow only one NULL. A second null value will become a duplicate. A unique index can be clustered or non-clustered, the default is clustered. While creating an index, the FILLFACTOR can be mentioned. The FILLFACTOR is a percentage to which the leaf level pages of the index are filled up. Similarly, PAD INDEX can be used to mention the number of non-leaf level pages that are filled. PAD INDEX cannot be used without fillfactor. A separate percentage value cannot be mentioned for PAD INDEX as it takes the fillfactor value only.
  3. In this slide, you need to explain to the students about a clustered index and a nonclustered index. Do not provide details on the type of indexes as they will be discussed later in the slides.
  4. In this slide, you need to explain how a clustered index searches for a particular string. You can refer to the Student Guide to explain the steps.
  5. In this slide, you need to explain how a nonclustered index searches for a particular string. You can refer to the Student Guide to explain the steps.
  6. In this slide, you need to explain the guidelines to be followed while creating an index.
  7. In this slide, you need to explain the syntax of the CREATE INDEX statement. In addition, you need to describe the various parameters of the CREATE INDEX statement. In this session, you will not teach the topic on creating XML indexes (given in the book). However, you can ask the students to read the topic at home. The concept will not be tested in the MT. CG Input: Before creating any index, please log on by using sa and execute the CreateTable.sql data file present in the Chapter 6\\Instep Demo folder.
  8. You can use the examples given in the Student Guide to clarify the concept to the students. Further, you can execute the following statements to explain the concept: Example: CLUSTERED INDEX CREATE CLUSTERED INDEX IX_EmployeeID ON Employee (EmployeeID) WITH FILLFACTOR = 10 Example: NONCLUSTERED INDEX CREATE NONCLUSTERED INDEX IDX_Employee_ManagerID ON Employee (ManagerID)
  9. In this slide, you need to explain the concept the XML Indexes to the students.
  10. Reiterate the concepts taught earlier by asking the given question.
  11. Reiterate the concepts taught earlier by asking the given question.
  12. Reiterate the concepts taught earlier by asking the given question.
  13. In this slide, you will explain how to disable, enable, rename, delete, and optimize indexes. You can use the examples given in the Student Guide to clarify the concept to the students. Further, you can execute the following statements to explain the concept: Example: (Disabling indexes) The following statement disables a nonclustered index, IdX_Employee_LoginID, on the Employee table: ALTER INDEX IdX_Employee_LoginID ON HumanResources.Employee DISABLE Example: (Enabling indexes) You can enable a disabled index by rebuilding it by using one of the following methods: ALTER INDEX statement with the REBUILD clause CREATE INDEX with the DROP_EXISTING clause DBCC DBREINDEX Example: (Renaming indexes) The following statement renames the IX_JobCandidate_EmployeeID index in the JobCandidate table to IX_EmployeeID: EXEC sp_rename &apos;HumanResources.JobCandidate.IX_JobCandidate_EmployeeID&apos;, &apos;IX_EmployeeID&apos;,&apos;index&apos; Example: (Dropping indexes) The following statement drops the IX_JobCandidate_EmployeeID index in the JobCandidate table: DROP INDEX IX_JobCandidate_EmployeeID ON HumanResources.JobCandidate; Example: (Optimizing indexes) The following statement helps you identify an index that contains a high level of fragmentation in the Employee table: SELECT a.index_id AS IndexID, name AS IndexName, avg_fragmentation_in_percent AS Fragmentation FROM sys.dm_db_index_physical_stats (DB_ID (N&apos;AdventureWorks&apos;), OBJECT_ID (&apos;HumanResources.Employee&apos;), NULL, NULL, NULL) AS a JOIN sys.indexes AS b on a.object_id = b.object_id and a.index_id = b.index_id ORDER BY Fragmentation DESC
  14. You need to ensure that after the end of this demo, the students are able to implement indexes in the tables. To perform this demo, you need to provide the SHOWPLAN permissions to the user account that you are using to perform the demo. CG Input: The table already contains an index on the ProductNumber column. The name of the index is AK_Product_ProductNumber. Therefore, before performing this demo, you need to ensure that you drop the existing index by executing the following statement: DROP INDEX [AK_Product_ProductNumber] ON [Production].Product] WITH ( ONLINE = OFF )   In the task 3 of the demo, the execution plan will display an icon of a clustered index scan. You can inform the students that this index is applied on the ProductID column. However, an index is to be applied on the ProductNumber column.
  15. You can summarize the session with the help of the Summary given in the Student Guide. In addition, you can ask the students to summarize what they have learned in this session.
  16. You can summarize the session with the help of the Summary given in the Student Guide. In addition, you can ask the students to summarize what they have learned in this session.