Switch to: V12V11V10V9V8V7V6V5

10. Indexes in SQL

This section will help you to see the whole picture how to work with Indexes using SQL way.

On Schema Definition

In SQL you can define indexing of a field(s) in few ways.

CREATE TABLE T1( 
    f1 LONG INDEXED UNIQUE
)
  • In CREATE TABLE using table constraint UNIQUE, to define in this way UNIQUE index also.
CREATE TABLE T1( 
    f1 LONG 
    CONSTRAINT cname UNIQUE (f1)
)
CREATE UNIQUE INDEX index_name ON TABLE_NAME( COLUMN, ... )

On Schema Changes

  • Use ALTER TABLE forms to add/remove/change fields and table constraints.
  • Also you can use DROP IDEX to drop indexes created by CREATE INDEX.

Show Indexes

  • You can use SHOW INDEXES command to see all indexes of a Table.