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

Is UNIQUE(), INDEX() different from UNIQUE INDEX()?

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

Problem

Is there any different how mysql treats

UNIQUE (column1, column2),
INDEX (column1)


and

UNIQUE INDEX (column1, column2)


and

UNIQUE (column1, column2)


In the latter, I think mysql will automatically creates index for UNIQUE to avoid duplicate records. Am I right?

Solution

UNIQUE (column1, column2) implies UNIQUE INDEX (column1, column2) because the INDEX keyword is optional. So an index is created. However, the MySQL 5.5 docs show that the INDEX (or KEY) keyword is mandatory so UNIQUE (column1, column2) should give an error

INDEX (column1, column2) does not mean UNIQUE INDEX (column1, column2): it means an index that does allow duplicate (column1, column2) pairs

Context

StackExchange Database Administrators Q#15566, answer score: 7

Revisions (0)

No revisions yet.