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);