SQL Server Indexes

IMPLEMENTING INDEXES
INTRODUCTION TO INDEXES
Indexes

  1. Indexes improve query performance by reducing I/O operations ( select, update, delete )
  2. Indexes are built on one or more columns in a table or  view ( keys)
  3. Indexes are automatically created for primary key and unique constraints

Index Types

  1. Clustered index ( like phone book ) –binary tree
  2. Leaf nodes contains actual data pages
  3. Root, intermediate, look
  4. Data sorted and stored based on index key
  5. Non clustaered index binary tree
  6. Intermediate nodes contain pointers to actual data pages
  7. Data not sorted based on key
  8. Unique, included, full text, xml

Index Guidelines- query optimizer
Non-Clustered

  1. Queries that do not return large data sets
  2. Queries that return exact matching ( where )
  3. Covered querry
  4. Columns with high degree of uniqueness (1-1 relationship)
  5. Group by columns

Clustered

  1. Queries that return large data sets
  2. Qeures that return ranges
  3. Columns with a high degree of uniqueness
  4. Foreign key columns
  5. Group by and order by

Database

  1. Avoid on indexing  heavily updated tasks
  2. Use many indexes on tables with little to no data modifications
  3. Avoid indexing small tables

Practical WORKING WITH INDEXES

  1. Primary key creates clustered index
  2. Tables à Indexes à right click and New index
  3. Fill factor work with leaf level node while pad index works with intermediate level node
  4. Covered index–  cover all columns in index=add non-key column into index

MAINTAINING & OPTIMIZING INDEXES
1)
Index Property à fragmentation à if total fragmentation <30% re organize( ), if >30% rebuild ( drop and created )
2)Database Engine tuning advisor run and see recommendation
3) SQL Profiler
Display estimated query plan, select and execute

Display actual query plan, select and execute

CLUSTERED INDEX , Non Cluster Idnex, unique Index ( just check box)
Tables –TableAà Indexà Right click and New
Optons: left all default except
Set fill factor specify how full sql server should make leave level of each index page when creating the index Pad Index specify space to leave open on each page in intermediate levels of the index Allow Online Indexing
—Creating covered indexes
Include include columns ( non covered key or non-key files)
Maintaining Index – rebuild or re organize

Tags:

Leave a Reply