SlideShare a Scribd company logo
1 of 58
INDEXES
This session will cover…..
 What are indexes and why they are used?
 Indexes may be either Clustered or Non-
Clustered.
 Types of indexes
 How to create indexes
Indexes 2
What are indexes and why they
are used?
 Every organization has its database and each and every day
with the increase in the data volume these organizations
has to deal with the problems relating to data retrieval and
accessing of data.
 There is need of system which will results into increase in
the data access speed.
 An index (in simple words it like index of any book eg.While
searching a word in Book we use index back of book to find
the occurrences of that word and its relevant page
numbers), which makes it easier for us to retrieval and
presentation of the data.
Indexes 3
 An Index is a system which provides faster
access to rows and for enforcing constraints.
 If we don't create any indexes then the SQL
engine searches every row in table (also
called as table scan). As the table data grows
to thousand, millions of rows and further then
searching without indexing becomes much
slower and becomes expensive.
Indexes 4
 Consider the following query on the Products
table of the Northwind database.This query
retrieves products in a specific price range.
 SELECT ProductID, ProductName, UnitPrice
FROM ProductsWHERE (UnitPrice > 12.5)
AND (UnitPrice < 14)
 currently no index.
 the database engine performs a scan and
examines each record to see if UnitPrice falls
between 12.5 and 14.
 Now imagine if we created an index on the
UnitPrice column.
 Each index entry would contain a copy of the
UnitPrice value for a row, and a reference (just
like a page number) to the row where the value
originated.
 SQL will sort these index entries into ascending
order.The index will allow the database to
quickly narrow in on the rows to satisfy the
query, and avoid scanning every row in the table.
 CREATE INDEX [IDX_UnitPrice] ON Products
(UnitPrice)
How It Works
Conceptually, we may think of an index as
shown in the diagram below. On the left,
each index entry contains the index key
(UnitPrice). Each entry also includes a
reference (which points) to the table rows
which share that particular value and from
which we can retrieve the required
information.
Clustered index
 A common analogy for a clustered index is a
phone book. A phone book still sorts entries
into alphabetical order.The difference is,
once we find a name in a phone book, we
have immediate access to the rest of the data
for the name, such as the phone number and
address.
 A clustered index is the most important index
you can apply to a table.
 If the database engine can use a clustered
index during a query, the database does not
need to follow references back to the rest of
the data, as happens with a nonclustered
index.
 The result is less work for the database, and
consequently, better performance for a query
using a clustered index.
A Disadvantage to Clustered
Indexes
 If we update a record and change the value of an
indexed column in a clustered index, the
database might need to move the entire row into
a new position to keep the rows in sorted order.
This behavior essentially turns an update query
into a DELETE followed by an INSERT, with an
obvious decrease in performance. A table's
clustered index can often be found on the
primary key or a foreign key column, because
key values generally do not change once a record
is inserted into the database.
Indexes may be either Clustered
or Non-Clustered.
 A clustered index stores data rows in the
table based on their key values. Each table
can have only one clustered index as the key
values in the data rows are unique and the
index is built on the unique key column.When
a table has a clustered index, it is known as a
clustered table.
Indexes 16
 Non-Clustered indexes have structures that
are different from the data rows.A non
clustered index key value is used to point to
data rows that contain the key value.This
value is known as row locator.
Indexes 17
Types of Indexes
In SQL Server 2005, indexes are created on
tables to increase the speed of data retrieval.
 UNIQUE INDEX
 FULLTEXT INDEX
 XML INDEX
Indexes 18
UNIQUE INDEX:
 A unique index does not allow any duplicate values
in the index field of a table.
 It ensures that every row in the table is unique.
 While designing a unique index, consider the
following guidelines:
 A unique index cannot be created if duplicate key values
exists in the table.
 Non-key columns can be included in a unique non-clustered
index.
Indexes 19
To create an index
 1. In Object Explorer, right-click the table for
which you want to create an index and
click Modify.

Indexes 20
Indexes 21
2. The table opens in Table Designer.
Indexes 22
3. From the Table Designer menu,
click Indexes/Keys.
Indexes 23
4. In the Indexes/Keys dialog box, click Add.
Indexes 24
 5. Select the new index in the Selected
Primary/Unique Key or Index list and set
properties for the index in the grid to the
right.
Indexes 25
Indexes 26
 6. Specify any other settings for the index and
click Close.

7.The index is created in the database when you
save the table.

SQL Server allows users create unique indexes
on unique columns such as the identity number
of the employee or student or whatever is the
unique key by which the component data are
identified.
Indexes 27
To create a unique index
 In Object Explorer, right-click the table and
click Modify.
 The table opens in Table Designer.
 From the Table Designer menu,
click Indexes/Keys.
 Click Add.The Selected Primary/Unique Key
or Index list displays the system-assigned
name of the new index.
Indexes 28
Indexes 29
5. In the grid, click Type.
Indexes 30
 6. Choose Index from the drop-down list to the
right of the property.

7. Under Column name, select the columns you
want to index.You can select up to 16 columns.
For optimal performance, select only one or two
columns per index. For each column you select,
indicate whether the index arranges values of
this column in ascending or descending order.

Indexes 31
Indexes 32
8. In the grid, click Is Unique.
Indexes 33
 9. Choose Yes from the drop-down list to the
right of the property.

10. Select the Ignore duplicate keys option if
you want to ignore new or updated data that
would create a duplicate key in the index
(with the INSERT or UPDATE statement).

Indexes 34
Indexes 35
11. The index is created in the database
when you save the table or diagram
Indexes 36
 note that unique indexes cannot be created
on a single column if the column contains
NULL in more than one row. Similarly indexes
cannot be created on multiple columns if the
combination of the columns contains NULL in
some rows.The NULL values are treated as
duplicate values.
Indexes 37
Clustered Index
 Clustered indexes can be created in SQL
Server databases. In such cases the logical
order of the index key values will be the same
as the physical order of rows in the table. A
table can have only one clustered index.
Indexes 38
 To create a clustered index
1. In Object Explorer, right-click the table for which you
want to create a clustered index and clickModify.
2.The table opens in Table Designer.
3. From the Table Designer menu, click Indexes/Keys.
4. In the Indexes/Keys dialog box, click Add.
5. Select the new index in the Selected Primary/Unique
Key or Index list.
6. In the grid, select Create as Clustered, and
choose Yes from the drop-down list to the right of the
property.

Indexes 39
7. The index is created in the database
when you save the table.
Indexes 40
Full-Text Index
 FullText Index helps to perform complex
queries against character data.
 These queries can include word or phrase
searching.We can create a full-text index on a
table or indexed view in a database.
 Only one full-text index is allowed per table
or indexed view.
Indexes 41
To create full-text indexes
 In Object Explorer, right-click the table for
which you want to create a full-text index and
clickModify.
 The table opens in Table Designer.
 From the Table Designer menu, click Fulltext
Index.
Indexes 42
Indexes 43
4.The Full-text Index dialog box opens. If the
database is not enabled for full text indexing
the dialog box will have the add button
disabled.To enable full text indexing for the
database, right click the database>Click
properties and check the Full text indexing
check box.
Indexes 44
Indexes 45
 5.Then create a catalog by right clicking on
Storage>FullText Catalog and creating a new
Catalog and entering the required
information in the dialog box that opens.
Indexes 46
Indexes 47
Indexes 48
6. Now open the Full Text Index property
dialog box by clicking on it in the Table
Designer menu.
Indexes 49
 7. Click Add.
8. Select the new index in the Selected Full-
text Index list and set properties for the
index in the grid to the right.
9.Your index is automatically saved in the
database when you save your table in Table
Designer. The index is available for
modification as soon as you create it.
Indexes 50
To change index properties
1. In Object Explorer, right-click the table
you want to open and click Modify.
2. From the Table Designer menu,
click Indexes/Keys.
3. Select the index from the Selected
Primary/Unique Key or Index list.
4. Change properties in the grid.
5.The changes are saved to the database
when you save the table.
Indexes 51
To rename an index
 1. In Object Explorer, right-click the table with
the index you want to rename and click Modify.
2. From the Table Designer menu,
click Indexes/Keys.
3. Select the index from the Selected
Primary/Unique Key or Index list.
4. In the grid, click Name and type a new name
into the text box.

Indexes 52
5. The changes are saved to the database
when you save the table.
Indexes 53
 Indexes can be deleted. Usually an index is
considered for deletion when the
performance of the INSERT,UPDATE and
DELETE operations are hindered by the
Index.

Indexes 54
To delete an index
1. In Object Explorer, right-click the table with
indexes you want to delete and click Modify.
2. From the Table Designer menu,
click Indexes/Keys.
3. In the Indexes/Keys dialog box, select the index
you want to delete.
4. Click Delete.
5.The index is deleted from the database when the
table is saved.
6. A similar procedure can be followed for deleting a
full text index by selecting Full text index from the
Table Designer and selecting the index name and
clicking delete button.
Indexes 55
FREETEXT( )
 FREETEXT( ) Is predicate used to search
columns containing character-based data
types. It will not match the exact word, but
the meaning of the words in the search
condition.
Indexes 56
CONTAINS( )
 CONTAINS( ) is similar to the Freetext but
with the difference that it takes one keyword
to match with the records, and if we want to
combine other words as well in the search
then we need to provide the “and” or “or” in
search else it will throw an error.
Indexes 57
Indexes 58

More Related Content

What's hot (20)

MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 
Sql joins
Sql joinsSql joins
Sql joins
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Subqueries
SubqueriesSubqueries
Subqueries
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Trigger
TriggerTrigger
Trigger
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
 
Sql views
Sql viewsSql views
Sql views
 
NESTED SUBQUERY.pptx
NESTED SUBQUERY.pptxNESTED SUBQUERY.pptx
NESTED SUBQUERY.pptx
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
 
Sql joins inner join self join outer joins
Sql joins inner join self join outer joinsSql joins inner join self join outer joins
Sql joins inner join self join outer joins
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Sequences and indexes
Sequences and indexesSequences and indexes
Sequences and indexes
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 

Viewers also liked

Nikkei stock market
Nikkei stock marketNikkei stock market
Nikkei stock marketAminafye
 
What do stock indexes show?
What do stock indexes show?What do stock indexes show?
What do stock indexes show?Brian Coil
 
From Summits To Indexes And Beyond (2)
From Summits To Indexes And Beyond (2)From Summits To Indexes And Beyond (2)
From Summits To Indexes And Beyond (2)ammann
 
Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Antonios Chatzipavlis
 
7 Stock Index
7 Stock Index7 Stock Index
7 Stock Indexukabuka
 
STOCK MARKET INDICES
STOCK MARKET INDICESSTOCK MARKET INDICES
STOCK MARKET INDICESRiyas Pk
 

Viewers also liked (9)

Nikkei stock market
Nikkei stock marketNikkei stock market
Nikkei stock market
 
What do stock indexes show?
What do stock indexes show?What do stock indexes show?
What do stock indexes show?
 
From Summits To Indexes And Beyond (2)
From Summits To Indexes And Beyond (2)From Summits To Indexes And Beyond (2)
From Summits To Indexes And Beyond (2)
 
Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014
 
Nikkei
Nikkei  Nikkei
Nikkei
 
Econ304 2 - Index Number
Econ304 2 - Index NumberEcon304 2 - Index Number
Econ304 2 - Index Number
 
7 Stock Index
7 Stock Index7 Stock Index
7 Stock Index
 
STOCK MARKET INDICES
STOCK MARKET INDICESSTOCK MARKET INDICES
STOCK MARKET INDICES
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 

Similar to Sql server ___________session_17(indexes)

Sql server lesson6
Sql server lesson6Sql server lesson6
Sql server lesson6Ala Qunaibi
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesJavier García Magna
 
Sql interview q&a
Sql interview q&aSql interview q&a
Sql interview q&aSyed Shah
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008wharrislv
 
Indexing techniques
Indexing techniquesIndexing techniques
Indexing techniquesHuda Alameen
 
Indexing Strategies
Indexing StrategiesIndexing Strategies
Indexing Strategiesjlaspada
 
Database index
Database indexDatabase index
Database indexRiteshkiit
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuningAnil Pandey
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 Andriy Krayniy
 
Db performance optimization with indexing
Db performance optimization with indexingDb performance optimization with indexing
Db performance optimization with indexingRajeev Kumar
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized tableAmrit Kaur
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questionsambika93
 
Microsoft excel training
Microsoft excel trainingMicrosoft excel training
Microsoft excel trainingEmilyE120
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management Systemsweetysweety8
 

Similar to Sql server ___________session_17(indexes) (20)

Sql server lesson6
Sql server lesson6Sql server lesson6
Sql server lesson6
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
 
Module08
Module08Module08
Module08
 
Module08
Module08Module08
Module08
 
Sql interview q&a
Sql interview q&aSql interview q&a
Sql interview q&a
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
 
MSSQL_Book.pdf
MSSQL_Book.pdfMSSQL_Book.pdf
MSSQL_Book.pdf
 
Oracle Index
Oracle IndexOracle Index
Oracle Index
 
Indexing techniques
Indexing techniquesIndexing techniques
Indexing techniques
 
Indexing Strategies
Indexing StrategiesIndexing Strategies
Indexing Strategies
 
Database index
Database indexDatabase index
Database index
 
ITB - UNIT 4.pdf
ITB - UNIT 4.pdfITB - UNIT 4.pdf
ITB - UNIT 4.pdf
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
 
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
 
Access 2007 lecture notes students
Access 2007 lecture notes studentsAccess 2007 lecture notes students
Access 2007 lecture notes students
 
Db performance optimization with indexing
Db performance optimization with indexingDb performance optimization with indexing
Db performance optimization with indexing
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
 
Dbms interview questions
Dbms interview questionsDbms interview questions
Dbms interview questions
 
Microsoft excel training
Microsoft excel trainingMicrosoft excel training
Microsoft excel training
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 

More from Ehtisham Ali

Sql server ___________session_20(ddl triggers)
Sql server  ___________session_20(ddl triggers)Sql server  ___________session_20(ddl triggers)
Sql server ___________session_20(ddl triggers)Ehtisham Ali
 
Sql server ___________session3-normailzation
Sql server  ___________session3-normailzationSql server  ___________session3-normailzation
Sql server ___________session3-normailzationEhtisham Ali
 
Sql server ___________session2-data_modeling
Sql server  ___________session2-data_modelingSql server  ___________session2-data_modeling
Sql server ___________session2-data_modelingEhtisham Ali
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)Ehtisham Ali
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)Ehtisham Ali
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)Ehtisham Ali
 
Sql server ___________session_15(data integrity)
Sql server  ___________session_15(data integrity)Sql server  ___________session_15(data integrity)
Sql server ___________session_15(data integrity)Ehtisham Ali
 
Sql server ___________session_11-12(joins)
Sql server  ___________session_11-12(joins)Sql server  ___________session_11-12(joins)
Sql server ___________session_11-12(joins)Ehtisham Ali
 
Sql server ___________session_10(group by clause)
Sql server  ___________session_10(group by clause)Sql server  ___________session_10(group by clause)
Sql server ___________session_10(group by clause)Ehtisham Ali
 
Sql server ___________session_1-intro
Sql server  ___________session_1-introSql server  ___________session_1-intro
Sql server ___________session_1-introEhtisham Ali
 
Sql server ___________session 3(sql 2008)
Sql server  ___________session 3(sql 2008)Sql server  ___________session 3(sql 2008)
Sql server ___________session 3(sql 2008)Ehtisham Ali
 
Sql server ___________session 2(sql 2008)
Sql server  ___________session 2(sql 2008)Sql server  ___________session 2(sql 2008)
Sql server ___________session 2(sql 2008)Ehtisham Ali
 
Sql server ___________session 1(sql 2008)
Sql server  ___________session 1(sql 2008)Sql server  ___________session 1(sql 2008)
Sql server ___________session 1(sql 2008)Ehtisham Ali
 
Sql server ___________data type of sql server
Sql server  ___________data type of sql serverSql server  ___________data type of sql server
Sql server ___________data type of sql serverEhtisham Ali
 
Sql server ___________data control language
Sql server  ___________data control languageSql server  ___________data control language
Sql server ___________data control languageEhtisham Ali
 
Sql server ___________ (advance sql)
Sql server  ___________  (advance sql)Sql server  ___________  (advance sql)
Sql server ___________ (advance sql)Ehtisham Ali
 

More from Ehtisham Ali (17)

Android tutorial
Android tutorialAndroid tutorial
Android tutorial
 
Sql server ___________session_20(ddl triggers)
Sql server  ___________session_20(ddl triggers)Sql server  ___________session_20(ddl triggers)
Sql server ___________session_20(ddl triggers)
 
Sql server ___________session3-normailzation
Sql server  ___________session3-normailzationSql server  ___________session3-normailzation
Sql server ___________session3-normailzation
 
Sql server ___________session2-data_modeling
Sql server  ___________session2-data_modelingSql server  ___________session2-data_modeling
Sql server ___________session2-data_modeling
 
Sql server ___________session_19(triggers)
Sql server  ___________session_19(triggers)Sql server  ___________session_19(triggers)
Sql server ___________session_19(triggers)
 
Sql server ___________session_18(stored procedures)
Sql server  ___________session_18(stored procedures)Sql server  ___________session_18(stored procedures)
Sql server ___________session_18(stored procedures)
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
 
Sql server ___________session_15(data integrity)
Sql server  ___________session_15(data integrity)Sql server  ___________session_15(data integrity)
Sql server ___________session_15(data integrity)
 
Sql server ___________session_11-12(joins)
Sql server  ___________session_11-12(joins)Sql server  ___________session_11-12(joins)
Sql server ___________session_11-12(joins)
 
Sql server ___________session_10(group by clause)
Sql server  ___________session_10(group by clause)Sql server  ___________session_10(group by clause)
Sql server ___________session_10(group by clause)
 
Sql server ___________session_1-intro
Sql server  ___________session_1-introSql server  ___________session_1-intro
Sql server ___________session_1-intro
 
Sql server ___________session 3(sql 2008)
Sql server  ___________session 3(sql 2008)Sql server  ___________session 3(sql 2008)
Sql server ___________session 3(sql 2008)
 
Sql server ___________session 2(sql 2008)
Sql server  ___________session 2(sql 2008)Sql server  ___________session 2(sql 2008)
Sql server ___________session 2(sql 2008)
 
Sql server ___________session 1(sql 2008)
Sql server  ___________session 1(sql 2008)Sql server  ___________session 1(sql 2008)
Sql server ___________session 1(sql 2008)
 
Sql server ___________data type of sql server
Sql server  ___________data type of sql serverSql server  ___________data type of sql server
Sql server ___________data type of sql server
 
Sql server ___________data control language
Sql server  ___________data control languageSql server  ___________data control language
Sql server ___________data control language
 
Sql server ___________ (advance sql)
Sql server  ___________  (advance sql)Sql server  ___________  (advance sql)
Sql server ___________ (advance sql)
 

Recently uploaded

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 

Recently uploaded (20)

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 

Sql server ___________session_17(indexes)

  • 2. This session will cover…..  What are indexes and why they are used?  Indexes may be either Clustered or Non- Clustered.  Types of indexes  How to create indexes Indexes 2
  • 3. What are indexes and why they are used?  Every organization has its database and each and every day with the increase in the data volume these organizations has to deal with the problems relating to data retrieval and accessing of data.  There is need of system which will results into increase in the data access speed.  An index (in simple words it like index of any book eg.While searching a word in Book we use index back of book to find the occurrences of that word and its relevant page numbers), which makes it easier for us to retrieval and presentation of the data. Indexes 3
  • 4.  An Index is a system which provides faster access to rows and for enforcing constraints.  If we don't create any indexes then the SQL engine searches every row in table (also called as table scan). As the table data grows to thousand, millions of rows and further then searching without indexing becomes much slower and becomes expensive. Indexes 4
  • 5.  Consider the following query on the Products table of the Northwind database.This query retrieves products in a specific price range.  SELECT ProductID, ProductName, UnitPrice FROM ProductsWHERE (UnitPrice > 12.5) AND (UnitPrice < 14)
  • 6.  currently no index.  the database engine performs a scan and examines each record to see if UnitPrice falls between 12.5 and 14.
  • 7.
  • 8.  Now imagine if we created an index on the UnitPrice column.  Each index entry would contain a copy of the UnitPrice value for a row, and a reference (just like a page number) to the row where the value originated.  SQL will sort these index entries into ascending order.The index will allow the database to quickly narrow in on the rows to satisfy the query, and avoid scanning every row in the table.
  • 9.  CREATE INDEX [IDX_UnitPrice] ON Products (UnitPrice)
  • 10. How It Works Conceptually, we may think of an index as shown in the diagram below. On the left, each index entry contains the index key (UnitPrice). Each entry also includes a reference (which points) to the table rows which share that particular value and from which we can retrieve the required information.
  • 11.
  • 12. Clustered index  A common analogy for a clustered index is a phone book. A phone book still sorts entries into alphabetical order.The difference is, once we find a name in a phone book, we have immediate access to the rest of the data for the name, such as the phone number and address.
  • 13.
  • 14.  A clustered index is the most important index you can apply to a table.  If the database engine can use a clustered index during a query, the database does not need to follow references back to the rest of the data, as happens with a nonclustered index.  The result is less work for the database, and consequently, better performance for a query using a clustered index.
  • 15. A Disadvantage to Clustered Indexes  If we update a record and change the value of an indexed column in a clustered index, the database might need to move the entire row into a new position to keep the rows in sorted order. This behavior essentially turns an update query into a DELETE followed by an INSERT, with an obvious decrease in performance. A table's clustered index can often be found on the primary key or a foreign key column, because key values generally do not change once a record is inserted into the database.
  • 16. Indexes may be either Clustered or Non-Clustered.  A clustered index stores data rows in the table based on their key values. Each table can have only one clustered index as the key values in the data rows are unique and the index is built on the unique key column.When a table has a clustered index, it is known as a clustered table. Indexes 16
  • 17.  Non-Clustered indexes have structures that are different from the data rows.A non clustered index key value is used to point to data rows that contain the key value.This value is known as row locator. Indexes 17
  • 18. Types of Indexes In SQL Server 2005, indexes are created on tables to increase the speed of data retrieval.  UNIQUE INDEX  FULLTEXT INDEX  XML INDEX Indexes 18
  • 19. UNIQUE INDEX:  A unique index does not allow any duplicate values in the index field of a table.  It ensures that every row in the table is unique.  While designing a unique index, consider the following guidelines:  A unique index cannot be created if duplicate key values exists in the table.  Non-key columns can be included in a unique non-clustered index. Indexes 19
  • 20. To create an index  1. In Object Explorer, right-click the table for which you want to create an index and click Modify.  Indexes 20
  • 22. 2. The table opens in Table Designer. Indexes 22
  • 23. 3. From the Table Designer menu, click Indexes/Keys. Indexes 23
  • 24. 4. In the Indexes/Keys dialog box, click Add. Indexes 24
  • 25.  5. Select the new index in the Selected Primary/Unique Key or Index list and set properties for the index in the grid to the right. Indexes 25
  • 27.  6. Specify any other settings for the index and click Close.  7.The index is created in the database when you save the table.  SQL Server allows users create unique indexes on unique columns such as the identity number of the employee or student or whatever is the unique key by which the component data are identified. Indexes 27
  • 28. To create a unique index  In Object Explorer, right-click the table and click Modify.  The table opens in Table Designer.  From the Table Designer menu, click Indexes/Keys.  Click Add.The Selected Primary/Unique Key or Index list displays the system-assigned name of the new index. Indexes 28
  • 30. 5. In the grid, click Type. Indexes 30
  • 31.  6. Choose Index from the drop-down list to the right of the property.  7. Under Column name, select the columns you want to index.You can select up to 16 columns. For optimal performance, select only one or two columns per index. For each column you select, indicate whether the index arranges values of this column in ascending or descending order.  Indexes 31
  • 33. 8. In the grid, click Is Unique. Indexes 33
  • 34.  9. Choose Yes from the drop-down list to the right of the property.  10. Select the Ignore duplicate keys option if you want to ignore new or updated data that would create a duplicate key in the index (with the INSERT or UPDATE statement).  Indexes 34
  • 36. 11. The index is created in the database when you save the table or diagram Indexes 36
  • 37.  note that unique indexes cannot be created on a single column if the column contains NULL in more than one row. Similarly indexes cannot be created on multiple columns if the combination of the columns contains NULL in some rows.The NULL values are treated as duplicate values. Indexes 37
  • 38. Clustered Index  Clustered indexes can be created in SQL Server databases. In such cases the logical order of the index key values will be the same as the physical order of rows in the table. A table can have only one clustered index. Indexes 38
  • 39.  To create a clustered index 1. In Object Explorer, right-click the table for which you want to create a clustered index and clickModify. 2.The table opens in Table Designer. 3. From the Table Designer menu, click Indexes/Keys. 4. In the Indexes/Keys dialog box, click Add. 5. Select the new index in the Selected Primary/Unique Key or Index list. 6. In the grid, select Create as Clustered, and choose Yes from the drop-down list to the right of the property.  Indexes 39
  • 40. 7. The index is created in the database when you save the table. Indexes 40
  • 41. Full-Text Index  FullText Index helps to perform complex queries against character data.  These queries can include word or phrase searching.We can create a full-text index on a table or indexed view in a database.  Only one full-text index is allowed per table or indexed view. Indexes 41
  • 42. To create full-text indexes  In Object Explorer, right-click the table for which you want to create a full-text index and clickModify.  The table opens in Table Designer.  From the Table Designer menu, click Fulltext Index. Indexes 42
  • 44. 4.The Full-text Index dialog box opens. If the database is not enabled for full text indexing the dialog box will have the add button disabled.To enable full text indexing for the database, right click the database>Click properties and check the Full text indexing check box. Indexes 44
  • 46.  5.Then create a catalog by right clicking on Storage>FullText Catalog and creating a new Catalog and entering the required information in the dialog box that opens. Indexes 46
  • 49. 6. Now open the Full Text Index property dialog box by clicking on it in the Table Designer menu. Indexes 49
  • 50.  7. Click Add. 8. Select the new index in the Selected Full- text Index list and set properties for the index in the grid to the right. 9.Your index is automatically saved in the database when you save your table in Table Designer. The index is available for modification as soon as you create it. Indexes 50
  • 51. To change index properties 1. In Object Explorer, right-click the table you want to open and click Modify. 2. From the Table Designer menu, click Indexes/Keys. 3. Select the index from the Selected Primary/Unique Key or Index list. 4. Change properties in the grid. 5.The changes are saved to the database when you save the table. Indexes 51
  • 52. To rename an index  1. In Object Explorer, right-click the table with the index you want to rename and click Modify. 2. From the Table Designer menu, click Indexes/Keys. 3. Select the index from the Selected Primary/Unique Key or Index list. 4. In the grid, click Name and type a new name into the text box.  Indexes 52
  • 53. 5. The changes are saved to the database when you save the table. Indexes 53
  • 54.  Indexes can be deleted. Usually an index is considered for deletion when the performance of the INSERT,UPDATE and DELETE operations are hindered by the Index.  Indexes 54
  • 55. To delete an index 1. In Object Explorer, right-click the table with indexes you want to delete and click Modify. 2. From the Table Designer menu, click Indexes/Keys. 3. In the Indexes/Keys dialog box, select the index you want to delete. 4. Click Delete. 5.The index is deleted from the database when the table is saved. 6. A similar procedure can be followed for deleting a full text index by selecting Full text index from the Table Designer and selecting the index name and clicking delete button. Indexes 55
  • 56. FREETEXT( )  FREETEXT( ) Is predicate used to search columns containing character-based data types. It will not match the exact word, but the meaning of the words in the search condition. Indexes 56
  • 57. CONTAINS( )  CONTAINS( ) is similar to the Freetext but with the difference that it takes one keyword to match with the records, and if we want to combine other words as well in the search then we need to provide the “and” or “or” in search else it will throw an error. Indexes 57