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

MySQL ADD KEY meaning

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

Problem

This code below is creating a primary key on table User, but Im not understanding the second ADD KEY (C_NATIONKEY), do you know what is doing? Its something about foreign keys?

ALTER TABLE USER
ADD PRIMARY KEY (C_USRKEY),
ADD KEY (C_NATIONKEY);

Solution

As per MySql documentation, KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition. This was implemented for compatibility with other database systems.
In your case ADD KEY will explicitly define index on that field.

Context

StackExchange Database Administrators Q#131415, answer score: 5

Revisions (0)

No revisions yet.