
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What does the KEY keyword mean in MySQL?
Key is synonymous to an index. If you want to create an index for a column, then use ‘Key’.
As stated in the official docs:
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.
The key can be used with Primary Key:
Let us first create a table. Here is the query to set primary key for a column “id”.
mysql> create table KeyDemo -> ( -> id int, -> primary key(id) -> ); Query OK, 0 rows affected (0.55 sec)
Inserting two records.
mysql> insert into KeyDemo values(1); Query OK, 1 row affected (0.12 sec) mysql> insert into KeyDemo values(2); Query OK, 1 row affected (0.14 sec)
To display all the records.
mysql> select *from KeyDemo;
Here is the output.
+----+ | id | +----+ | 1 | | 2 | +----+ 2 rows in set (0.00 sec)
- Related Articles
- What does the explicit keyword mean in C++?
- What does the restrict keyword mean in C++?
- What does the volatile keyword mean in C++?
- MySQL CREATE statement with KEY keyword
- What does INT(7) in MySQL mean?
- What does the slash mean in a MySQL query?
- What does parenthesis mean in MySQL SELECT (COLNAME)?
- While creating a MySQL table use the reserved keyword ‘Key’
- What does the keyword var do in C#?
- What does “unsigned” in MySQL mean and when to use it?
- What does it mean by select 1 from MySQL table?
- What does geometry mean?
- What does psychology mean?
- What does humus mean?
- How can I define a column of a MySQL table PRIMARY KEY without using the PRIMARY KEY keyword?

Advertisements