Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 14 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
14
Dung lượng
1,01 MB
Nội dung
Instructor Inputs Session 8 ¤NIIT Instructor Inputs 8.3 This session includes section one of Chapter 6 of the Student Guide. Slide 1 Slide 1 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 In this session, you will learn to: Create and manage indexes Objectives Begin the session by sharing the objectives with the students. In this session, the students will understand the requirements of indexes. Next, they will learn how to create and manage indexes. Session Overview 8.4 Instructor Inputs ¤NIIT Slide 2 Slide 2 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 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 Identifying Type of Indexes In this topic, you need to explain the concept of indexes to the students. Begin with showing the flash presentation. The presentation explains the usage of indexes. Inputs for Flash Presentation You can use the following points to explain: Screen 1 Explain that data for every table is stored in data pages. Screen 2 A table is internally represented as a collection of data pages. With increase in the volume of data the number of data pages increases. Screen 3 When a user searches for data, the database engine searches through all the data pages. This takes time to retrieve the required data. Highlight the time taken by the query to execute. ¤NIIT Instructor Inputs 8.5 Screen 4 SQL Server allows implementing indexes. An index is a structure that stores the key values and pointers to those values. After an index is implemented, if a user queries for data, the index is searched for the required value and the record is picked from the data page whose pointer is stored in the index. This increases the speed of the data search. Bring the attention of the students to the reduced time spent to process the user query. While teaching the topic, mention the advantages of using indexes. 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. You can mention the following for indexes: Creating multiple indexes on a column is not a good practice. Therefore, before applying an index, it is necessary to check the requirement of an index. Indexes are always created on columns that are queried most. When constraints like the primary key constraint are applied on a table, indexes are created in the database engine. 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. 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. 8.6 Instructor Inputs ¤NIIT Slide 3 Slide 3 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 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. Identifying Type of Indexes (Contd.) In this topic, you need to explain the concepts of clustered index and nonclustered indexes. You need to only explain the definitions of these concepts. Slide 4 Slide 4 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 Working of a Clustered Index: Identifying Type of Indexes (Contd.) In this topic, you need to explain how a clustered index searches for a particular string. You can refer to the Student Guide to explain the steps. ¤NIIT Instructor Inputs 8.7 Slide 5 Slide 5 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 Working of a NonClustered Index: Identifying Type of Indexes (Contd.) In this topic, you need to explain how a nonclustered index searches for a particular string. You can refer to the Student Guide to explain the steps. Slide 6 Slide 6 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 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 Creating Indexes In this topic, you need to explain the guidelines to be followed while creating an index. The guidelines are given in the Student Guide. 8.8 Instructor Inputs ¤NIIT Slide 7 Slide 7 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 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}] Creating Indexes (Contd.) In this topic, 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. 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. ¤NIIT Instructor Inputs 8.9 N ote Slide 8 Slide 8 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 <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… Creating Indexes (Contd.) Demonstrate how to create an index by executing the example given in the Student Guide. Before creating the index, log on by using sa and execute the CreateTable.sql data file present in the Chapter 6\Instep Demo folder. This file will drop the Employee table created when teaching chapter 3. It will further create a copy of the Employee table of the HumanResources schema and name it as Employee. It will further copy the data from the HumanResources.Employee table to the Employee table. Before running this inline demo, you need to create an Employee table by executing the CreateTable.sql script file present in the Datafiles_for_faculty\QMDS2005\Chapter 06 folder of the TIRM CD. During the demo you will apply an index on the Employee table created by the sql script. This is because the HumanResources.Employee table already has few indexes applied on it. 8.10 Instructor Inputs ¤NIIT Slide 9 Slide 9 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 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 Creating XML Indexes In this topic, you need to explain the concept the XML Indexes to the students. Explain that you can create XML indexes on the columns that store the XML data. The XML indexes are categorized as primary and secondary XML indexes. Demonstrate these concepts using the example given in the Student Guide. You can read more about these topics on the msdn. Slide 10 Slide 10 of 17Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 Just a minute Which type of index implements physical sorting of data? Answer: Clustered index [...]... is created with the CREATE INDEX command Session 8 Ver 1.0 Slide 16 of 17 Summarize the session Slide 17 Querying and Managing Data using SQL Server 2005 Summary (Contd.) 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 8. 14 Instructor Inputs Session 8 Slide 17 of 17 NIIT ... execution Ver 1.0 Session 8 Slide 15 of 17 In task 3 of the solution, the execution plan will display an icon of a clustered index scan Tell the students that this index is applied on the ProductID column However, in the demo, an index is to be applied on the ProductNumber column NIIT Instructor Inputs 8. 13 Slide 16 Querying and Managing Data using SQL Server 2005 Summary In this session, you learned... Session 8 Slide 12 of 17 Reiterate the concepts taught earlier by asking the given question NIIT Instructor Inputs 8. 11 Slide 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… Session 8 Ver 1.0 Slide 13 of 17 In this topic, you will explain how to disable, enable, rename, delete,... 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 8. 12 Instructor Inputs Session 8 Slide 14 of 17 NIIT At the end of this demo, the students will be able to create indexes Demo Handling Tips To perform this demo, you need to provide the SHOWPLAN permissions to the user... Answer: Primary XML index Session 8 Ver 1.0 Slide 11 of 17 Reiterate the concepts taught earlier by asking the given question Slide 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 2 3 4 Fill Factor Pad Index Path Index Value Index Answer: 1 Fill Factor Ver 1.0 Session 8 Slide 12 of 17 Reiterate . Instructor Inputs Session 8 ¤NIIT Instructor Inputs 8. 3 This session includes section one of Chapter 6 of the Student Guide. Slide 1 Slide 1 of 1 7Session 8 Ver. 1.0 Querying. Next, they will learn how to create and manage indexes. Session Overview 8. 4 Instructor Inputs ¤NIIT Slide 2 Slide 2 of 1 7Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005. creating an index. The guidelines are given in the Student Guide. 8. 8 Instructor Inputs ¤NIIT Slide 7 Slide 7 of 1 7Session 8 Ver. 1.0 Querying and Managing Data using SQL Server 2005 Syntax: CREATE