SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Implementing Indexes

Objectives
In this lesson, you will learn to:
 Create a clustered index
 Create a nonclustered index
 Use the Index Tuning Wizard
 Understand Index Enhancements




©NIIT                                SQL/Lesson 7/Slide 1 of 32
Implementing Indexes

Getting Started
 An index is an internal table structure that SQL Server uses
  to provide quick access to rows of a table based on the
  values of one or more columns
 Advantages of Using Indexes
     Improve the speed of the execution of queries
     Enforce uniqueness of data
     Speed up joins between tables




©NIIT                                        SQL/Lesson 7/Slide 2 of 32
Implementing Indexes

Getting Started (Contd.)
 Disadvantages of Using Indexes
     Takes time to create an index
     Takes large amount of disk space to store data along with
      the original data source—the table
     Gets updated each time the data is modified
 Types of Indexes
     Clustered index
     Nonclustered index


©NIIT                                        SQL/Lesson 7/Slide 3 of 32
Implementing Indexes

Getting Started (Contd.)
 Clustered Index
     In a clustered index:
        ® The   data is physically sorted
        ® Only   one clustered index can be created per table
 Nonclustered Index
     In a nonclustered index:
        ® Thephysical order of the rows is not the same as the
         index order


©NIIT                                           SQL/Lesson 7/Slide 4 of 32
Implementing Indexes

Getting Started (Contd.)
        ® Nonclustered  indexes are typically created on columns
         used in joins and WHERE clauses, and whose values
         may be modified frequently
        ® SQLServer creates nonclustered indexes by default
         when the CREATE INDEX command is given
        ® There   can be as many as 249 nonclustered indexes per
         table




©NIIT                                         SQL/Lesson 7/Slide 5 of 32
Implementing Indexes

Getting Started (Contd.)
 Indexes and Heap Structures
     SQL Server supports indexes defined on any column in a
      table, including computed columns
        ® Ifa table does not have any clustered index, data is not
          stored in a particular order. This structure is called a
          heap




©NIIT                                          SQL/Lesson 7/Slide 6 of 32
Implementing Indexes

Getting Started (Contd.)
 Features of Indexes
     Indexes accelerate queries that join tables, and perform
      sorting and grouping.
     Indexes can be used to enforce uniqueness of rows.
     Indexes are useful on columns in which the majority of
      data is unique.
     When you modify the data of an indexed column, the
      associated indexes are updated automatically.
     You require time and resources to maintain indexes. You
      should not create an index that is not used frequently.

©NIIT                                        SQL/Lesson 7/Slide 7 of 32
Implementing Indexes

Getting Started (Contd.)
     A clustered index should be created before a
      nonclustered index. A clustered index changes the order
      of rows. A nonclustered index would need to be rebuilt if it
      is built before a clustered index
     Typically, nonclustered indexes are created on foreign
      keys.
 Syntax
        CREATE [UNIQUE] [CLUSTERED|NONCLUSTERED]
        INDEX index_name
        ON table_name(column_name[,column_name]…)

©NIIT                                          SQL/Lesson 7/Slide 8 of 32
Implementing Indexes

7.D.1 Optimizing Query Execution
 The ExternalCandidate table contains a large amount of data.
  The first name of each candidate and the name of the
  recruitment agency are required to create a report. However,
  it takes a long time to execute the following query.
    SELECT    vFirstName, cName
    FROM ExternalCandidate JOIN
    RecruitmentAgencies
    ON
    ExternalCandidate.cAgencyCode =
    RecruitmentAgencies.cAgencyCode
    Suggest and implement a solution for faster data retrieval.
©NIIT                                         SQL/Lesson 7/Slide 9 of 32
Implementing Indexes

Task List
 Identify how to speed up data retrieval
 Draft the statement to create an index
 Create the index in the database
 Verify that the index has been created
 Verify that the query execution is faster




©NIIT                                         SQL/Lesson 7/Slide 10 of 32
Implementing Indexes

Identify how to speed up data retrieval
 Indexes are used to:
     Speed up data retrieval
     Enforce the uniqueness of rows
 Result:
     To speed up data retrieval, use indexes




©NIIT                                       SQL/Lesson 7/Slide 11 of 32
Implementing Indexes

Draft the statement to create an index
 Action:
     The tables on which the index would be created are:
      ExternalCandidate and RecruitmentAgencies
     The attributes on which the index would be created are:
      cAgencyCode of ExternalCandidate and cAgencyCode of
      RecruitmentAgencies
     The types of indexes to be created are:
      ExternalCandidate - Nonclustered index;
      RecruitmentAgencies - Clustered index
     The names of the indexes to be created are idxRecruitment
      and idxExternalCandidate
©NIIT                                      SQL/Lesson 7/Slide 12 of 32
Implementing Indexes

Create the index in the database
 Action:
     In the Query Analyzer window, type:
        CREATE NONCLUSTERED INDEX idxExternalCandidate
        ON ExternalCandidate(cAgencyCode)
        CREATE CLUSTERED INDEX       idxRecruitment
        ON RecruitmentAgencies(cAgencyCode)
     Press F5 to execute the code




©NIIT                                       SQL/Lesson 7/Slide 13 of 32
Implementing Indexes

Verify that the index has been created
 To verify that the index has been created, use the sp_helpindex
  command
 Syntax
  sp_helpindex table_name
 Action:
     In the Query Analyzer window, type:
        sp_helpindex ExternalCandidate
     Press F5 to execute the command
     In the Query Analyzer window, type:
        sp_helpindex RecruitmentAgencies
     Press F5 to execute the command
©NIIT                                       SQL/Lesson 7/Slide 14 of 32
Implementing Indexes

Verify that the query execution is faster
 Action:
     Execute the query after creating the index. If there is a lot of
      data, you can note the difference in speed




©NIIT                                          SQL/Lesson 7/Slide 15 of 32
Implementing Indexes

Just a Minute…
 How many clustered indexes can be created per table?
 Which index organizes data logically but does not store data
  physically?




©NIIT                                       SQL/Lesson 7/Slide 16 of 32
Implementing Indexes

Index Tuning Wizard
 Index Tuning Wizard available in SQL Server is used to select
  and create the best possible set of indexes and information
  regarding a database
 Uses of the Index Tuning Wizard
     For a given workload, the best possible combination of
      indexes for a database is recommended
     The effects of the proposed recommendation about the
      indexes, distribution of queries among tables, and the query
      performance in the workload will be analyzed
     For a small set of problem queries, the way to tune the
      database will be recommended
     It will specify the advanced options such as disk space
      constraints that can be customized
©NIIT                                        SQL/Lesson 7/Slide 17 of 32
Implementing Indexes

7.D.2 Using the Index Tuning Wizard
 You have created the following indexes on the Department
  table:
  CREATE NONCLUSTERED INDEX idxdepcode
  ON DEPARTMENT(cDepartmentCode)
  CREATE NONCLUSTERED INDEX idxdepname
  ON DEPARTMENT(vDepartmentName)
  CREATE NONCLUSTERED INDEX idxdephead
  ON DEPARTMENT(vDepartmentHead)
  CREATE NONCLUSTERED INDEX idxdeplocation
  ON DEPARTMENT(vlocation)
©NIIT                                     SQL/Lesson 7/Slide 18 of 32
Implementing Indexes

7.D.2 Using the Index Tuning Wizard (Contd.)
 Analyze the use of these indexes on the Department table
  when the following query is executed:
  SELECT Requisition.cRequisitionCode,
  Position.vDescription,vDepartmentName
  FROM Position
  JOIN Requisition
  ON Requisition.cPositionCode=
  Position.cPositionCode
  JOIN Department
  ON Requisition.cDepartmentCode=
  Department.cDepartmentCode

©NIIT                                     SQL/Lesson 7/Slide 19 of 32
Implementing Indexes

Task List
 Identify a method to analyze the use of indexes
 Perform the analysis
 Verify that the analysis has been performed




©NIIT                                       SQL/Lesson 7/Slide 20 of 32
Implementing Indexes

Identify a method to analyze the use of indexes
 Result:
     Use the Index Tuning Wizard to analyze the use of
      indexes




©NIIT                                      SQL/Lesson 7/Slide 21 of 32
Implementing Indexes

Perform the analysis
 Action:
     Perform the analysis using the Index Tuning Wizard




©NIIT                                      SQL/Lesson 7/Slide 22 of 32
Implementing Indexes

Verify that the analysis has been performed
 Action:
     You can use the following command to view the indexes
      present on the Department table:
        sp_helpindex Department
 Observe that, as recommended by the Index Tuning Wizard,
  the extra indexes have been removed




©NIIT                                    SQL/Lesson 7/Slide 23 of 32
Implementing Indexes

Index Enhancements
 Fill Factor
    FILLFACTOR clause improves performance of the system
     by minimizing the amount of page splitting that occurs each
     time an index page becomes full
    Syntax
      CREATE CLUSTERED INDEX index_name
                       ON table_name (column_name)
                       WITH FILLFACTOR =
                       percentage_fillfactor
 Pad_Index
     Specifies the space to leave open on each page (node) in
 ©NIIT the intermediate levels of the index SQL/Lesson 7/Slide 24 of 32
Implementing Indexes

Index Enhancements (Contd.)
 Implications of NULL in Unique Indexes:
     In a table, a unique index cannot be created on a single
      column if that column contains NULL in more than one row
 DBCC SHOWCONTIG:
     The DBCC SHOWCONTIG command is primarily used to
       find out why the table or the index is heavily fragmented
     Syntax
    DBCC SHOWCONTIG
     [
       (table_id [, index_id])
     ]
 ©NIIT                                        SQL/Lesson 7/Slide 25 of 32
Implementing Indexes

Index Enhancements (Contd.)
 The DBCC INDEXDEFRAG:
    The DBCC INDEXDEFRAG command is used to
     defragment clustered and secondary indexes of the
     specified table or view
    Syntax
   DBCC INDEXDEFRAG
      ( { database_name | database_id | 0 }
          , { table_name | table_id | 'view_name' | view_id }
          , { index_name | index_id }
      )


©NIIT                                        SQL/Lesson 7/Slide 26 of 32
Implementing Indexes

Just a Minute…
 Susan wants to minimize the amount of page splitting that
  occurs each time an index page is full. What should she use?




©NIIT                                      SQL/Lesson 7/Slide 27 of 32
Implementing Indexes

Index Enhancements (Contd.)
 Index Selection:
     A detailed query analysis is required to determine which
      index to involve in a query process. This involves:
        ® Examining   the search clauses to identify the columns
         referenced
        ® Knowing the importance of the data to determine the
         usefulness of the index
        ® Ranking   the queries in the order of importance




©NIIT                                          SQL/Lesson 7/Slide 28 of 32
Implementing Indexes

Performance Considerations (Contd.)
 Index Usage Criteria:
     SQL Server cannot use an index until and unless the query
      contains a column in a valid search argument or join clause
      that matches at least the first column of the index




 ©NIIT                                       SQL/Lesson 7/Slide 29 of 32
Implementing Indexes

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

©NIIT                                         SQL/Lesson 7/Slide 30 of 32
Implementing Indexes

Summary (Contd.)
 A nonclustered index should be built on an attribute which is
  normally used in joins and the WHERE clause. The values of
  this attribute may often change.
 A nonclustered index is the default index that is created with
  the CREATE INDEX command.
 The Index Tuning Wizard can be used to analyze the optimal
  use of indexes in the query entered in the Query Analyzer
  window.
 SQL Server provides the FILLFACTOR clause to improve
  performance of the system by minimizing the amount of page
  splitting that occurs each time an index page becomes full.

©NIIT                                       SQL/Lesson 7/Slide 31 of 32
Implementing Indexes

Summary (Contd.)
 The DBCC SHOWCONTIG command is mainly used to find
  out whether the table or index is heavily fragmented. Table
  fragmentation normally occurs when a large number of insert
  and update operations are performed on the table.
 The DBCC INDEXDEFRAG command is used to defragment
  clustered and secondary indexes of the specified table or view.




©NIIT                                       SQL/Lesson 7/Slide 32 of 32

Weitere ähnliche Inhalte

Was ist angesagt?

CIS 336 Final Exam 2 (Devry)s
CIS 336 Final Exam 2 (Devry)sCIS 336 Final Exam 2 (Devry)s
CIS 336 Final Exam 2 (Devry)scritterc07
 
Cis 336 final exam 2
Cis 336 final exam 2Cis 336 final exam 2
Cis 336 final exam 2prasaaanna2
 
BIS 245 OUTLET Achievement Education--bis245outlet.com
BIS 245 OUTLET Achievement Education--bis245outlet.comBIS 245 OUTLET Achievement Education--bis245outlet.com
BIS 245 OUTLET Achievement Education--bis245outlet.comagathachristie179
 
BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
 BIS 245 OUTLET Inspiring Innovation--bis245outlet.com BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
BIS 245 OUTLET Inspiring Innovation--bis245outlet.comwilliamwordsworth45
 
BIS 245 OUTLET Introduction Education--bis245outlet.com
BIS 245 OUTLET Introduction Education--bis245outlet.comBIS 245 OUTLET Introduction Education--bis245outlet.com
BIS 245 OUTLET Introduction Education--bis245outlet.comagathachristie291
 
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.comBIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.comthomashard72
 
BIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.comBIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.comagathachristie241
 
BIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.comBIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.comKeatonJennings120
 
BIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.comBIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.comagathachristie256
 
BIS 245 Lessons in Excellence / bis245.com
BIS 245 Lessons in Excellence / bis245.comBIS 245 Lessons in Excellence / bis245.com
BIS 245 Lessons in Excellence / bis245.comkopiko33
 
Management productivity tools1
Management productivity tools1Management productivity tools1
Management productivity tools1Hari Krishnan
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle databaseSalman Memon
 

Was ist angesagt? (20)

CIS 336 Final Exam 2 (Devry)s
CIS 336 Final Exam 2 (Devry)sCIS 336 Final Exam 2 (Devry)s
CIS 336 Final Exam 2 (Devry)s
 
Cis 336 final exam 2
Cis 336 final exam 2Cis 336 final exam 2
Cis 336 final exam 2
 
Sql ch 4
Sql ch 4Sql ch 4
Sql ch 4
 
BIS 245 OUTLET Achievement Education--bis245outlet.com
BIS 245 OUTLET Achievement Education--bis245outlet.comBIS 245 OUTLET Achievement Education--bis245outlet.com
BIS 245 OUTLET Achievement Education--bis245outlet.com
 
BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
 BIS 245 OUTLET Inspiring Innovation--bis245outlet.com BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
BIS 245 OUTLET Inspiring Innovation--bis245outlet.com
 
BIS 245 OUTLET Introduction Education--bis245outlet.com
BIS 245 OUTLET Introduction Education--bis245outlet.comBIS 245 OUTLET Introduction Education--bis245outlet.com
BIS 245 OUTLET Introduction Education--bis245outlet.com
 
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.comBIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
BIS 245 HOMEWORK Lessons in Excellence--bis245homework.com
 
BIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.comBIS 245 HOMEWORK Redefined Education--bis245homework.com
BIS 245 HOMEWORK Redefined Education--bis245homework.com
 
BIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.comBIS 245 HOMEWORK Become Exceptional--bis245homework.com
BIS 245 HOMEWORK Become Exceptional--bis245homework.com
 
BIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.comBIS 245 HOMEWORK Introduction Education--bis245homework.com
BIS 245 HOMEWORK Introduction Education--bis245homework.com
 
BIS 245 Lessons in Excellence / bis245.com
BIS 245 Lessons in Excellence / bis245.comBIS 245 Lessons in Excellence / bis245.com
BIS 245 Lessons in Excellence / bis245.com
 
Dbms practical list
Dbms practical listDbms practical list
Dbms practical list
 
Sql wksht-7
Sql wksht-7Sql wksht-7
Sql wksht-7
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 
Part1 (2 Examene)
Part1 (2 Examene)Part1 (2 Examene)
Part1 (2 Examene)
 
Management productivity tools1
Management productivity tools1Management productivity tools1
Management productivity tools1
 
Part2 (1 Examen)
Part2 (1 Examen)Part2 (1 Examen)
Part2 (1 Examen)
 
SQL(database)
SQL(database)SQL(database)
SQL(database)
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
 

Andere mochten auch (8)

Sql xp 10
Sql xp 10Sql xp 10
Sql xp 10
 
Create table
Create tableCreate table
Create table
 
Spanning Tree Protocol
Spanning Tree ProtocolSpanning Tree Protocol
Spanning Tree Protocol
 
Joining Formalities
Joining FormalitiesJoining Formalities
Joining Formalities
 
Induction and Orientation
Induction and OrientationInduction and Orientation
Induction and Orientation
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 
WTF - Why the Future Is Up to Us - pptx version
WTF - Why the Future Is Up to Us - pptx versionWTF - Why the Future Is Up to Us - pptx version
WTF - Why the Future Is Up to Us - pptx version
 

Ähnlich wie Sql xp 07

07 qmds2005 session10
07 qmds2005 session1007 qmds2005 session10
07 qmds2005 session10Niit Care
 
11 qmds2005 session16
11 qmds2005 session1611 qmds2005 session16
11 qmds2005 session16Niit Care
 
Dbms narrative question answers
Dbms narrative question answersDbms narrative question answers
Dbms narrative question answersshakhawat02
 
Sql interview question part 4
Sql interview question part 4Sql interview question part 4
Sql interview question part 4kaashiv1
 
Sql interview question part 4
Sql interview question part 4Sql interview question part 4
Sql interview question part 4kaashiv1
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterizationRiteshkiit
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net coreSam Nasr, MCSA, MVP
 
Business Intelligence Technology Presentation
Business Intelligence Technology PresentationBusiness Intelligence Technology Presentation
Business Intelligence Technology PresentationJohn Paredes
 
KoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginnersKoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginnersTobias Koprowski
 
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginnersKoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginnersTobias Koprowski
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005rainynovember12
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...Dave Stokes
 
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 ToolsSage 300 ERP CS
 

Ähnlich wie Sql xp 07 (20)

07 qmds2005 session10
07 qmds2005 session1007 qmds2005 session10
07 qmds2005 session10
 
Module08
Module08Module08
Module08
 
Module08
Module08Module08
Module08
 
11 qmds2005 session16
11 qmds2005 session1611 qmds2005 session16
11 qmds2005 session16
 
Dbms narrative question answers
Dbms narrative question answersDbms narrative question answers
Dbms narrative question answers
 
Sql interview question part 4
Sql interview question part 4Sql interview question part 4
Sql interview question part 4
 
Ebook4
Ebook4Ebook4
Ebook4
 
Sql interview question part 4
Sql interview question part 4Sql interview question part 4
Sql interview question part 4
 
Database in Android
Database in AndroidDatabase in Android
Database in Android
 
Query parameterization
Query parameterizationQuery parameterization
Query parameterization
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Business Intelligence Technology Presentation
Business Intelligence Technology PresentationBusiness Intelligence Technology Presentation
Business Intelligence Technology Presentation
 
KoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginnersKoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginners
 
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginnersKoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
 
Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005Optimizing Data Accessin Sq Lserver2005
Optimizing Data Accessin Sq Lserver2005
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Sq lite
Sq liteSq lite
Sq lite
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
 
Notepad tutorial
Notepad tutorialNotepad tutorial
Notepad tutorial
 
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
 

Mehr von 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
 

Kürzlich hochgeladen

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Kürzlich hochgeladen (20)

Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

Sql xp 07

  • 1. Implementing Indexes Objectives In this lesson, you will learn to: Create a clustered index Create a nonclustered index Use the Index Tuning Wizard Understand Index Enhancements ©NIIT SQL/Lesson 7/Slide 1 of 32
  • 2. Implementing Indexes Getting Started An index is an internal table structure that SQL Server uses to provide quick access to rows of a table based on the values of one or more columns Advantages of Using Indexes Improve the speed of the execution of queries Enforce uniqueness of data Speed up joins between tables ©NIIT SQL/Lesson 7/Slide 2 of 32
  • 3. Implementing Indexes Getting Started (Contd.) Disadvantages of Using Indexes Takes time to create an index Takes large amount of disk space to store data along with the original data source—the table Gets updated each time the data is modified Types of Indexes Clustered index Nonclustered index ©NIIT SQL/Lesson 7/Slide 3 of 32
  • 4. Implementing Indexes Getting Started (Contd.) Clustered Index In a clustered index: ® The data is physically sorted ® Only one clustered index can be created per table Nonclustered Index In a nonclustered index: ® Thephysical order of the rows is not the same as the index order ©NIIT SQL/Lesson 7/Slide 4 of 32
  • 5. Implementing Indexes Getting Started (Contd.) ® Nonclustered indexes are typically created on columns used in joins and WHERE clauses, and whose values may be modified frequently ® SQLServer creates nonclustered indexes by default when the CREATE INDEX command is given ® There can be as many as 249 nonclustered indexes per table ©NIIT SQL/Lesson 7/Slide 5 of 32
  • 6. Implementing Indexes Getting Started (Contd.) Indexes and Heap Structures SQL Server supports indexes defined on any column in a table, including computed columns ® Ifa table does not have any clustered index, data is not stored in a particular order. This structure is called a heap ©NIIT SQL/Lesson 7/Slide 6 of 32
  • 7. Implementing Indexes Getting Started (Contd.) Features of Indexes Indexes accelerate queries that join tables, and perform sorting and grouping. Indexes can be used to enforce uniqueness of rows. Indexes are useful on columns in which the majority of data is unique. When you modify the data of an indexed column, the associated indexes are updated automatically. You require time and resources to maintain indexes. You should not create an index that is not used frequently. ©NIIT SQL/Lesson 7/Slide 7 of 32
  • 8. Implementing Indexes Getting Started (Contd.) A clustered index should be created before a nonclustered index. A clustered index changes the order of rows. A nonclustered index would need to be rebuilt if it is built before a clustered index Typically, nonclustered indexes are created on foreign keys. Syntax CREATE [UNIQUE] [CLUSTERED|NONCLUSTERED] INDEX index_name ON table_name(column_name[,column_name]…) ©NIIT SQL/Lesson 7/Slide 8 of 32
  • 9. Implementing Indexes 7.D.1 Optimizing Query Execution The ExternalCandidate table contains a large amount of data. The first name of each candidate and the name of the recruitment agency are required to create a report. However, it takes a long time to execute the following query. SELECT vFirstName, cName FROM ExternalCandidate JOIN RecruitmentAgencies ON ExternalCandidate.cAgencyCode = RecruitmentAgencies.cAgencyCode Suggest and implement a solution for faster data retrieval. ©NIIT SQL/Lesson 7/Slide 9 of 32
  • 10. Implementing Indexes Task List Identify how to speed up data retrieval Draft the statement to create an index Create the index in the database Verify that the index has been created Verify that the query execution is faster ©NIIT SQL/Lesson 7/Slide 10 of 32
  • 11. Implementing Indexes Identify how to speed up data retrieval Indexes are used to: Speed up data retrieval Enforce the uniqueness of rows Result: To speed up data retrieval, use indexes ©NIIT SQL/Lesson 7/Slide 11 of 32
  • 12. Implementing Indexes Draft the statement to create an index Action: The tables on which the index would be created are: ExternalCandidate and RecruitmentAgencies The attributes on which the index would be created are: cAgencyCode of ExternalCandidate and cAgencyCode of RecruitmentAgencies The types of indexes to be created are: ExternalCandidate - Nonclustered index; RecruitmentAgencies - Clustered index The names of the indexes to be created are idxRecruitment and idxExternalCandidate ©NIIT SQL/Lesson 7/Slide 12 of 32
  • 13. Implementing Indexes Create the index in the database Action: In the Query Analyzer window, type: CREATE NONCLUSTERED INDEX idxExternalCandidate ON ExternalCandidate(cAgencyCode) CREATE CLUSTERED INDEX idxRecruitment ON RecruitmentAgencies(cAgencyCode) Press F5 to execute the code ©NIIT SQL/Lesson 7/Slide 13 of 32
  • 14. Implementing Indexes Verify that the index has been created To verify that the index has been created, use the sp_helpindex command Syntax sp_helpindex table_name Action: In the Query Analyzer window, type: sp_helpindex ExternalCandidate Press F5 to execute the command In the Query Analyzer window, type: sp_helpindex RecruitmentAgencies Press F5 to execute the command ©NIIT SQL/Lesson 7/Slide 14 of 32
  • 15. Implementing Indexes Verify that the query execution is faster Action: Execute the query after creating the index. If there is a lot of data, you can note the difference in speed ©NIIT SQL/Lesson 7/Slide 15 of 32
  • 16. Implementing Indexes Just a Minute… How many clustered indexes can be created per table? Which index organizes data logically but does not store data physically? ©NIIT SQL/Lesson 7/Slide 16 of 32
  • 17. Implementing Indexes Index Tuning Wizard Index Tuning Wizard available in SQL Server is used to select and create the best possible set of indexes and information regarding a database Uses of the Index Tuning Wizard For a given workload, the best possible combination of indexes for a database is recommended The effects of the proposed recommendation about the indexes, distribution of queries among tables, and the query performance in the workload will be analyzed For a small set of problem queries, the way to tune the database will be recommended It will specify the advanced options such as disk space constraints that can be customized ©NIIT SQL/Lesson 7/Slide 17 of 32
  • 18. Implementing Indexes 7.D.2 Using the Index Tuning Wizard You have created the following indexes on the Department table: CREATE NONCLUSTERED INDEX idxdepcode ON DEPARTMENT(cDepartmentCode) CREATE NONCLUSTERED INDEX idxdepname ON DEPARTMENT(vDepartmentName) CREATE NONCLUSTERED INDEX idxdephead ON DEPARTMENT(vDepartmentHead) CREATE NONCLUSTERED INDEX idxdeplocation ON DEPARTMENT(vlocation) ©NIIT SQL/Lesson 7/Slide 18 of 32
  • 19. Implementing Indexes 7.D.2 Using the Index Tuning Wizard (Contd.) Analyze the use of these indexes on the Department table when the following query is executed: SELECT Requisition.cRequisitionCode, Position.vDescription,vDepartmentName FROM Position JOIN Requisition ON Requisition.cPositionCode= Position.cPositionCode JOIN Department ON Requisition.cDepartmentCode= Department.cDepartmentCode ©NIIT SQL/Lesson 7/Slide 19 of 32
  • 20. Implementing Indexes Task List Identify a method to analyze the use of indexes Perform the analysis Verify that the analysis has been performed ©NIIT SQL/Lesson 7/Slide 20 of 32
  • 21. Implementing Indexes Identify a method to analyze the use of indexes Result: Use the Index Tuning Wizard to analyze the use of indexes ©NIIT SQL/Lesson 7/Slide 21 of 32
  • 22. Implementing Indexes Perform the analysis Action: Perform the analysis using the Index Tuning Wizard ©NIIT SQL/Lesson 7/Slide 22 of 32
  • 23. Implementing Indexes Verify that the analysis has been performed Action: You can use the following command to view the indexes present on the Department table: sp_helpindex Department Observe that, as recommended by the Index Tuning Wizard, the extra indexes have been removed ©NIIT SQL/Lesson 7/Slide 23 of 32
  • 24. Implementing Indexes Index Enhancements Fill Factor FILLFACTOR clause improves performance of the system by minimizing the amount of page splitting that occurs each time an index page becomes full Syntax CREATE CLUSTERED INDEX index_name ON table_name (column_name) WITH FILLFACTOR = percentage_fillfactor Pad_Index Specifies the space to leave open on each page (node) in ©NIIT the intermediate levels of the index SQL/Lesson 7/Slide 24 of 32
  • 25. Implementing Indexes Index Enhancements (Contd.) Implications of NULL in Unique Indexes: In a table, a unique index cannot be created on a single column if that column contains NULL in more than one row DBCC SHOWCONTIG: The DBCC SHOWCONTIG command is primarily used to find out why the table or the index is heavily fragmented Syntax DBCC SHOWCONTIG [ (table_id [, index_id]) ] ©NIIT SQL/Lesson 7/Slide 25 of 32
  • 26. Implementing Indexes Index Enhancements (Contd.) The DBCC INDEXDEFRAG: The DBCC INDEXDEFRAG command is used to defragment clustered and secondary indexes of the specified table or view Syntax DBCC INDEXDEFRAG ( { database_name | database_id | 0 } , { table_name | table_id | 'view_name' | view_id } , { index_name | index_id } ) ©NIIT SQL/Lesson 7/Slide 26 of 32
  • 27. Implementing Indexes Just a Minute… Susan wants to minimize the amount of page splitting that occurs each time an index page is full. What should she use? ©NIIT SQL/Lesson 7/Slide 27 of 32
  • 28. Implementing Indexes Index Enhancements (Contd.) Index Selection: A detailed query analysis is required to determine which index to involve in a query process. This involves: ® Examining the search clauses to identify the columns referenced ® Knowing the importance of the data to determine the usefulness of the index ® Ranking the queries in the order of importance ©NIIT SQL/Lesson 7/Slide 28 of 32
  • 29. Implementing Indexes Performance Considerations (Contd.) Index Usage Criteria: SQL Server cannot use an index until and unless the query contains a column in a valid search argument or join clause that matches at least the first column of the index ©NIIT SQL/Lesson 7/Slide 29 of 32
  • 30. Implementing Indexes Summary In this lesson, you learned that: Indexes are created to enhance the performance of queries. There are two types of indexes – clustered and nonclustered. Indexes are created using the CREATE INDEX statement. Data is physically sorted in a clustered index. Clustered indexes should be built on an attribute whose values are unique and do not change often. In a nonclustered index, the physical order of rows is not the same as that of the index order. ©NIIT SQL/Lesson 7/Slide 30 of 32
  • 31. Implementing Indexes Summary (Contd.) A nonclustered index should be built on an attribute which is normally used in joins and the WHERE clause. The values of this attribute may often change. A nonclustered index is the default index that is created with the CREATE INDEX command. The Index Tuning Wizard can be used to analyze the optimal use of indexes in the query entered in the Query Analyzer window. SQL Server provides the FILLFACTOR clause to improve performance of the system by minimizing the amount of page splitting that occurs each time an index page becomes full. ©NIIT SQL/Lesson 7/Slide 31 of 32
  • 32. Implementing Indexes Summary (Contd.) The DBCC SHOWCONTIG command is mainly used to find out whether the table or index is heavily fragmented. Table fragmentation normally occurs when a large number of insert and update operations are performed on the table. The DBCC INDEXDEFRAG command is used to defragment clustered and secondary indexes of the specified table or view. ©NIIT SQL/Lesson 7/Slide 32 of 32