Table of Contents
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.
- In CREATE TABLE when you define a field. See also CREATE TABLE
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) )
- Using CREATE INDEX command.
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.