1

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);

1 Answer 1

2

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.

1
  • In MySQL, the PRIMARY KEY is not just an INDEX, but also constrained to be UNIQUE and (for Engine=InnoDB), "clustered" with the data.
    – Rick James
    Mar 7, 2016 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.