KEY is a reserved word that appears in several contexts. In MySQL and MariaDB, KEY is a synonym for INDEX in CREATE TABLE and ALTER TABLE statements, letting you create secondary indexes that improve query performance. Across all SQL dialects, KEY is also part of composite keywords such as PRIMARY KEY and FOREIGN KEY, which enforce entity-integrity and referential-integrity rules respectively. A PRIMARY KEY uniquely identifies each row, automatically creating a unique index; a FOREIGN KEY ensures that column values exist in the referenced table. When used alone (without PRIMARY or FOREIGN) KEY has no meaning outside MySQL-compatible engines, so code portability requires caution. KEY names must be unique within a table, and composite keys can include multiple columns. Dropping or altering a key may be blocked if dependent constraints exist.
PRIMARY KEY, FOREIGN KEY, UNIQUE, INDEX, CONSTRAINT
MySQL 3.23 (KEY as synonym for INDEX). PRIMARY KEY and FOREIGN KEY appear in SQL-92.
In MySQL they are synonyms inside CREATE TABLE and ALTER TABLE. Other dialects require CREATE INDEX and do not recognize KEY on its own.
Yes, use ALTER TABLE ... DROP PRIMARY KEY, but first ensure no foreign keys depend on it or the statement will fail.
Most engines allow up to 16 columns, but the combined key length must fit within the index size limits specialized per engine.
In older MySQL versions adding an index could lock the table for writes. Modern versions with ALGORITHM=INPLACE or ONLINE minimize locking, but availability depends on engine and version.