The CREATE INDEX statement is used to create indexes in tables.
Note: Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So, only create indexes on columns that will be frequently searched against.
Syntax for create index
CREATE INDEX index_name
ON table_name (column1, column2, ...);
Syntax for UNIQUE create index
CREATE UNIQUE INDEX index_name
ON table_name (column1, column2, ...);
DROP INDEX Statement
The DROP INDEX statement is used to delete an index in a table.
ALTER TABLE table_name
DROP INDEX index_name;
Let's apply this with some examples
Today I am using customer_payment database
There are two tables within this database
customers and payment
To create index on a table
Create index index name ins_cus
On customers (customer_name, payment_id)
To create unique index where duplicate values are not allowed
Create unique index index name ins_pay
On payment(payment_mode, payment_id);
Here Error occurred as both payment mode and payment ID has duplicate values
So instead I am using item_id as column name
To drop index from the table
Alter table payment
Drop index ins_pay;
that's all for today Hope you all will get some help from this video
If it's so then don't forget to subscribe my channel Code with Neha and press the Bell Icon for Regular Updates
See you in the next video till then Stay Safe Stay Happy
#mysql
#mysqltutorial
#mysqltutorialforbeginners
#mysqldba
#mysqltutorials
#mysqldatabase
#indexinMySQL
#MySQLindex
#coding
#mysqlindex
#indexinmysql
#indexinMySQL
#howtocreateindexinmysql
#howtocreateindexinMySQL
#createrindexinmysql
#createindexinMySQL
#createindexinmysqldatabase
#mysqltutorialindexinginmysql
#indexinginmySQL
#indexinginmysql
#indexinginmysqltutorial
#indexconstraint
#indexconstraintinmysql
#indexconstraintinsql
#indexconstraintinmySQL
#indexinsql
#howtocreateindexinsql
#indexinginmysql
#indexinginmysqldatabase
#indexinginMySQL
#indexinginMySQLdatabase