SlideShare a Scribd company logo
“Database Management Systems”
CS-222
Lecture 00
“INDEXES”
Dr. Muhammad Muneer Umar
By:
Lecturer in Computer Science
Institute of Computing
KUST, Pakistan
INDEXES
• A database index is a data structure that improves the speed of operations
in a table.
• Indexes can be created using one or more columns, providing the basis for
both rapid random lookups and efficient ordering of access to records.
• Practically, indexes are also a type of tables, which keep primary key or
index field and a pointer to each record into the actual table
• The users cannot see the indexes, they are just used to speed up queries
and will be used by the Database Search Engine to locate records very fast.
• Slow on UPDATE and INSERT Queries because the database needs to insert
or update the index values as well.
SIMPLE AND UNIQUE INDEX
• A unique index means that two rows cannot have the same index
value. Here is the syntax to create an Index on a table.
• CREATE UNIQUE INDEX index_name ON table_name
( column1, column2,...);
• Just omit the UNIQUE keyword from the query to create a simple
index. A Simple index allows duplicate values in a table.
SIMPLE AND UNIQUE INDEX
• A unique index means that two rows cannot have the same index value. Here is the syntax to
create an Index on a table.
• CREATE UNIQUE INDEX index_name ON table_name ( column1,
column2,...);
• Just omit the UNIQUE keyword from the query to create a simple index. A Simple index allows
duplicate values in a table.
• If you want to index the values in a column in a descending order, you
can add the reserved word DESC after the column name.
• CREATE UNIQUE INDEX index_name ON table_name
( column1 DESC);
ALTER with INDEX
• There are four types of statements for adding indexes to a table −
• ALTER TABLE tbl_name ADD PRIMARY KEY (column_list)
− This statement adds a PRIMARY KEY, which means that the indexed values must be unique
and cannot be NULL.
• ALTER TABLE tbl_name ADD UNIQUE index_name (column_list)
− This statement creates an index for which the values must be unique (except for the NULL
values, which may appear multiple times).
• ALTER TABLE tbl_name ADD INDEX index_name (column_list)
• − This adds an ordinary index in which any value may appear more than once.
• ALTER TABLE tbl_name ADD FULLTEXT index_name (col_list) − This creates a
special FULLTEXT index that is used for text-searching purposes.
ALTER with INDEX
• You can drop any INDEX by using the DROP clause along with the
ALTER command.
• ALTER TABLE table_name DROP INDEX(column_list);
Lecture 17 (Week 11) - MYSQL INDEXES.pptx

More Related Content

PPT
Module08
PPT
Module08
PPT
Lec 1 = introduction to structured query language (sql)
PPT
15925 structured query
PPT
Introduction to Structured Query Language (SQL).ppt
PPT
Introduction to Structured Query Language (SQL) (1).ppt
PDF
DBMS and SQL Questions and Answers (1).pdf
PPTX
Data Definition Language Commands in DBMS
Module08
Module08
Lec 1 = introduction to structured query language (sql)
15925 structured query
Introduction to Structured Query Language (SQL).ppt
Introduction to Structured Query Language (SQL) (1).ppt
DBMS and SQL Questions and Answers (1).pdf
Data Definition Language Commands in DBMS

Similar to Lecture 17 (Week 11) - MYSQL INDEXES.pptx (20)

PPTX
Introduction of sql server indexing
PPTX
Database indexing techniques
PPTX
02 database oprimization - improving sql performance - ent-db
PPTX
SQL Joins Basic and Fundamentals
PPTX
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
PPTX
9. index and index organized table
PPTX
Aggregate functions in SQL.pptx
PPTX
More Complex SQL and Concurrency ControlModule 4.pptx
PPTX
Sql server ___________session_17(indexes)
PDF
Session 1 - Databases-JUNE 2023.pdf
PPTX
Aggregate functions in SQL.pptx
PPTX
SQL UNIT FOUR.pptxDiscDiscoverabilitDiscoverability Scorey Scoreoverability S...
PPTX
2..basic queries.pptx
PPTX
shs tvl ict_Programming Introduction to SQl.pptx
PPT
Sql Tutorials
PDF
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
PPTX
Oracle Index
PPTX
4 SQL DML.pptx ASHEN WANNIARACHCHI USESS
PPTX
Sql performance tuning
Introduction of sql server indexing
Database indexing techniques
02 database oprimization - improving sql performance - ent-db
SQL Joins Basic and Fundamentals
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
9. index and index organized table
Aggregate functions in SQL.pptx
More Complex SQL and Concurrency ControlModule 4.pptx
Sql server ___________session_17(indexes)
Session 1 - Databases-JUNE 2023.pdf
Aggregate functions in SQL.pptx
SQL UNIT FOUR.pptxDiscDiscoverabilitDiscoverability Scorey Scoreoverability S...
2..basic queries.pptx
shs tvl ict_Programming Introduction to SQl.pptx
Sql Tutorials
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
Oracle Index
4 SQL DML.pptx ASHEN WANNIARACHCHI USESS
Sql performance tuning
Ad

Recently uploaded (20)

PPTX
Modelling in Business Intelligence , information system
PPT
Predictive modeling basics in data cleaning process
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PDF
Microsoft Core Cloud Services powerpoint
PPT
DATA COLLECTION METHODS-ppt for nursing research
PDF
Transcultural that can help you someday.
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PDF
Data Engineering Interview Questions & Answers Batch Processing (Spark, Hadoo...
PDF
How to run a consulting project- client discovery
PPTX
modul_python (1).pptx for professional and student
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PDF
annual-report-2024-2025 original latest.
PPTX
importance of Data-Visualization-in-Data-Science. for mba studnts
PPTX
Leprosy and NLEP programme community medicine
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Modelling in Business Intelligence , information system
Predictive modeling basics in data cleaning process
Acceptance and paychological effects of mandatory extra coach I classes.pptx
CEE 2 REPORT G7.pptxbdbshjdgsgjgsjfiuhsd
IBA_Chapter_11_Slides_Final_Accessible.pptx
Galatica Smart Energy Infrastructure Startup Pitch Deck
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Introduction-to-Cloud-ComputingFinal.pptx
Microsoft Core Cloud Services powerpoint
DATA COLLECTION METHODS-ppt for nursing research
Transcultural that can help you someday.
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Data Engineering Interview Questions & Answers Batch Processing (Spark, Hadoo...
How to run a consulting project- client discovery
modul_python (1).pptx for professional and student
Qualitative Qantitative and Mixed Methods.pptx
annual-report-2024-2025 original latest.
importance of Data-Visualization-in-Data-Science. for mba studnts
Leprosy and NLEP programme community medicine
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Ad

Lecture 17 (Week 11) - MYSQL INDEXES.pptx

  • 1. “Database Management Systems” CS-222 Lecture 00 “INDEXES” Dr. Muhammad Muneer Umar By: Lecturer in Computer Science Institute of Computing KUST, Pakistan
  • 2. INDEXES • A database index is a data structure that improves the speed of operations in a table. • Indexes can be created using one or more columns, providing the basis for both rapid random lookups and efficient ordering of access to records. • Practically, indexes are also a type of tables, which keep primary key or index field and a pointer to each record into the actual table • The users cannot see the indexes, they are just used to speed up queries and will be used by the Database Search Engine to locate records very fast. • Slow on UPDATE and INSERT Queries because the database needs to insert or update the index values as well.
  • 3. SIMPLE AND UNIQUE INDEX • A unique index means that two rows cannot have the same index value. Here is the syntax to create an Index on a table. • CREATE UNIQUE INDEX index_name ON table_name ( column1, column2,...); • Just omit the UNIQUE keyword from the query to create a simple index. A Simple index allows duplicate values in a table.
  • 4. SIMPLE AND UNIQUE INDEX • A unique index means that two rows cannot have the same index value. Here is the syntax to create an Index on a table. • CREATE UNIQUE INDEX index_name ON table_name ( column1, column2,...); • Just omit the UNIQUE keyword from the query to create a simple index. A Simple index allows duplicate values in a table. • If you want to index the values in a column in a descending order, you can add the reserved word DESC after the column name. • CREATE UNIQUE INDEX index_name ON table_name ( column1 DESC);
  • 5. ALTER with INDEX • There are four types of statements for adding indexes to a table − • ALTER TABLE tbl_name ADD PRIMARY KEY (column_list) − This statement adds a PRIMARY KEY, which means that the indexed values must be unique and cannot be NULL. • ALTER TABLE tbl_name ADD UNIQUE index_name (column_list) − This statement creates an index for which the values must be unique (except for the NULL values, which may appear multiple times). • ALTER TABLE tbl_name ADD INDEX index_name (column_list) • − This adds an ordinary index in which any value may appear more than once. • ALTER TABLE tbl_name ADD FULLTEXT index_name (col_list) − This creates a special FULLTEXT index that is used for text-searching purposes.
  • 6. ALTER with INDEX • You can drop any INDEX by using the DROP clause along with the ALTER command. • ALTER TABLE table_name DROP INDEX(column_list);