Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 16 February 2024

Create Index in MARIADB

In MariaDB, you can create, drop, and alter indexes using similar syntax to other SQL databases. Below are examples illustrating these operations:

1. Creating an Index:

-- Create an index named idx_LastName on the LastName column of the Customers table

CREATE INDEX idx_LastName

ON Customers (LastName);

2. Dropping an Index:

-- Drop the index idx_LastName from the Customers table

DROP INDEX idx_LastName

ON Customers;

3. Altering a Table to Add an Index:

-- Add an index named idx_LastName on the LastName column of the Customers table

ALTER TABLE Customers

ADD INDEX idx_LastName (LastName);

4. Altering a Table to Drop an Index:

-- Drop the index idx_LastName from the Customers table using ALTER TABLE

ALTER TABLE Customers

DROP INDEX idx_LastName;

These SQL statements demonstrate the process of creating, altering, and dropping an index in MariaDB. Ensure that you replace Customers, LastName, and idx_LastName with your actual table name, column name, and index name, respectively. Also, make sure to have proper permissions before executing these commands.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.