HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMajor

CREATE INDEX vs ALTER TABLE ADD INDEX - MySQLism, or SQL Standard?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
createsqlmysqlismstandardindexaltertableadd

Problem

Just came across a weird issue, whereby depending on how I create an index, an index name is required.

http://dev.mysql.com/doc/refman/5.5/en/create-index.html

http://dev.mysql.com/doc/refman/5.5/en/alter-table.html

CREATE INDEX `random_name` ON `my_table` (`my_column`); # Requires an index name

ALTER TABLE `my_table` ADD INDEX (`my_column`); # Does not require an index name


It seems to me that the CREATE INDEX call, should not make index name required. I'm wondering if this is a MySQLism, or a SQL standard?

Solution

I don't think that the SQL standard defines how to create indexes at all.

A quote from this Wikipedia page:


Standardization


There is no standard about creating indexes because the ISO SQL
Standard does not cover physical aspects. Indexes are one of the
physical parts of database conception among others like storage
(tablespace or filegroups). RDBMS vendors all give a CREATE INDEX
syntax with some specific options which depends on functionalities
they provide to customers.

The Postgres manual seems to support this here:


There are no provisions for indexes in the SQL standard.

More evidence under this related question on SO.

Context

StackExchange Database Administrators Q#46623, answer score: 25

Revisions (0)

No revisions yet.